Reputation: 593
Is there any substitute for CFNotificationCenterAddObserver
in Swift
?
In Apple doc's I only find the reference to Objective-C, but I can't find any related code to use with Swift. Any idea?
The code I'm trying to write would be as follows in Objective-C:
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
displayStatusChanged,
CFSTR("com.apple.iokit.hid.displayStatus"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
Edit: It's not a NSNotification
(Apple Doc) that I am trying to use as in this question, but an CFNotification
(Apple Doc).
Upvotes: 1
Views: 2752
Reputation: 352
CFNotificationCenterAddObserver is available in Swift now. See apple docs.
func CFNotificationCenterAddObserver(_ center: CFNotificationCenter!,
_ observer: UnsafePointer<Void>,
_ callBack: CFNotificationCallback,
_ name: CFString!,
_ object: UnsafePointer<Void>,
_ suspensionBehavior: CFNotificationSuspensionBehavior)
Upvotes: 1