提问人:lurning too koad 提问时间:2/1/2023 最后编辑:Paulw11lurning too koad 更新时间:2/1/2023 访问量:34
默认的 NotificationCenter 属性到底是什么?
What exactly is the default NotificationCenter property?
问:
我想创建一个额外的实例,将我的内部通知与系统通知分开。但是,当我查看类实现时,我不明白我在看什么。NotificationCenter
open class NotificationCenter : NSObject {
open class var default: NotificationCenter { get }
}
吸气剂在哪里?究竟会得到什么?这是我期待看到的:default
extension NotificationCenter {
static let default = NotificationCenter()
}
该属性是我们只是看不到的单例,而 getter 只是返回它吗?default
static
要实现我自己的自定义中心,我可以按以下方式声明它吗?
extension NotificationCenter {
static let custom = NotificationCenter()
}
答:
2赞
Paulw11
2/1/2023
#1
NotificationCenter.default
获取应用程序的默认实例,该实例是单一实例。NotificationCenter
iOS 框架不是开源的,所以当你查看定义时,你看到的是它公开的接口,而不是实现,它可能看起来非常像你期望看到的代码。NotificationCenter.default
事实上,您可以使用NotificationCenter
NotificationCenter()
评论
NotificationCenter.default