CFNotificationCenterAddObserver

Has anyone figured out how to call CFNotificationCenterAddObserver() from Swift yet?


Session 224 had the following example:


CFNotificationCenterAddObserver(nc,
  nil,
  { _ in self.reloadModel() },
  "com.example.app-model-updated",
  nil,
  .DeliverImmediately)


However, I can't get this to compile. Xcode 6.4b4 gives the following error:

Cannot invoke 'CFNotificationCenterAddObserver' with an argument list of type '(CFNotificationCenter!, nil, (_) -> _, String, nil, CFNotificationSuspensionBehavior)'

Xcode 7 is more helpful and complains about captures:

> A C function pointer cannot be formed from a closure that captures context


I can get it to compile if I change the closure to contain only a call to print(). Kinda misses the point since most of the time you'd want to capture a reference to an object you want to act on.

CFNotificationCenterAddObserver
 
 
Q