我正在尝试为CFNotificationCenter
设置观察者。
文档中说明:
name
要观察的通知名称。如果为NULL,则针对对象发布的任何通知调用回调。 如果center是Darwin通知中心,则此值不能为NULL。
据我所知,Swift中不存在NULL
。那么这个参数应该是什么呢?
以下内容编译正常,但空白字符串不是NULL
:
CFNotificationCenterAddObserver(
CFNotificationCenterGetDistributedCenter(),
UnsafeMutableRawPointer?.none,
receiveNotification,
"" as CFString,
UnsafeRawPointer?.none,
CFNotificationSuspensionBehavior.deliverImmediately
)
我已经尝试了
CFString?
,NSNull
和NSNull as String
,但编译器报错。我是否误解了文档?如何为name参数提供NULL值?
nil
是什么情况? - Martin Rnil
。 - Kishan Bhatiya