Observing a Notification
suggest changeSwift
func testNotification(notification: NSNotification) {
let myObject = notification.userInfo?["someKey"] as? MyObject
}
This method is Swift 2. It runs only after this object has been registered for the notification. The cast is nil when someKey is missing or is not a MyObject.
Objective-C
- (void)testNotification:(NSNotification *)notification {
NSDictionary *userInfo = notification.userInfo;
MyObject *myObject = [userInfo objectForKey:@"someKey"];
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents