Because I'm sick of misspelling a selector name I figured I'd try to do some notification stuff with blocks instead of selectors.
I've put together some sample code that doesn't seem to work because I'm unable to access self
var currentString : String?
// Type alias the notificaitonBlock
typealias notificationBlock = (NSNotification?) -> ()
// in this case note is an NSNotification?
let strNotification : notificationBlock = { notification in
if let msg = notification?.object as? String {
self.currentString = msg
}
}
Assuming this code worked I would register it with:
nc.addObserverForName(UIDeviceOrientationDidChangeNotification,
object: self,
queue: NSOperationQueue.currentQueue(),
usingBlock: strNotification)
Xcode is giving me the following error:
NotificationTests.swift:49:4: 'NotificationTests -> () -> NotificationTests' does not have a member named 'currentString'
which implies self isn't pointing to the class but the block or something?