Message with sender and object

I don't seem to know how to send a notification with an object and a sender.

I can send a notification with the name, sender and user information. Cm:

- (void)postNotificationName:(NSString *)notificationName
                      object:(id)notificationSender
                    userInfo:(NSDictionary *)userInfo

And I can publish NSNotification with the object, but not associate the sender with it:

NSNotification *notification = [NSNotification notificationWithName:name
                                                             object:someObject];
[[NSNotificationCenter defaultCenter] postNotification:notification];

Can someone tell me how to send a notification with (a) the object and (b) the sender’s link?

+3
source share
1 answer

In both methods that you suggest, the variable objectrepresents the sender of the notification, and this can be anything. To provide additional objects with a notification, you can transfer the dictionary with your objects to userInfo.

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                      someObject, @"someObject",
                                      anotherObject, @"anotherObject", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:name
                                                    object:sender
                                                  userInfo:options];
+16
source

All Articles