Tchelow
Tchelow

Reputation: 593

CFNotificationCenterAddObserver in Swift

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

Answers (1)

zooster
zooster

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

Related Questions