【发布时间】:2020-02-05 10:54:57
【问题描述】:
我正在尝试为CFNotificationCenter 设置一个观察者。
documentation 声明:
名称
要观察的通知的名称。如果为 NULL,则为对象发布的任何通知调用回调。 如果 center 是 Darwin 通知中心,则该值不能为 NULL。
据我了解,NULL 在 Swift 中不存在。那么这个论点应该是什么呢?
以下编译正常,但空白字符串不是NULL:
CFNotificationCenterAddObserver(
CFNotificationCenterGetDistributedCenter(),
UnsafeMutableRawPointer?.none,
receiveNotification,
"" as CFString,
UnsafeRawPointer?.none,
CFNotificationSuspensionBehavior.deliverImmediately
)
我尝试过CFString?、NSNull 和NSNull as String,但编译器报错。
我是否误解了文档?如何为 name 参数提供 NULL 值?
【问题讨论】:
-
nil呢? -
你可以试试
nil -
@user28434 这是真的。
Null在 Swift 中不存在,但nil存在。 -
@Roberto,但概念相同,名称不同。
标签: ios swift core-foundation swift5.1