I created a program to send and receive events through NSNotification. Now i need to send data along with the event. Can anyone suggest me how to do this in coding in Objective-C??
There are two ways - one, you can pass any one object in with a notification - look at
+ (id)notificationWithName:(NSString *)aName object:(id)anObject
The second thing is, you can also pass an optional dictionary with as many objects as you like in it, you just need to have both sides agree on the keys used to store and retrieve the objects. That call is:
+ (id)notificationWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)userInfo
You can always pass a nil for either anObject or userInfo in either call.
An example call that sends a notification directly (you don't have to construct the notification first if you do not want to):
[[NSNotifcationCenter defaultCenter] postNotificationName:@"MyNotification" object:myObjectToSend];
There's also a variant of that call with userInfo added on, just as there is for notification construction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With