Observing a Notification

suggest change

Swift

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"];
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents