/* The notification name */
Const NSString *resultofappendingtwostringsnotification =
@ "Resultofappendingtwostringsnotification"; /* Keys inside the dictionary, our notification sends */
Const NSString
*resultofappendingtwostringsfirststringinfokey = @ "firststring";
Const NSString
*resultofappendingtwostringssecondstringinfokey = @ "secondstring";
Const NSString
*resultofappendingtwostringsresultstringinfokey = @ "resultstring";
Send Notification method
-(void) broadcastnotification{
NSString *firstname = @ "Anthony";
NSString *lastname = @ "Robbins";
NSString *fullname = [FirstName stringbyappendingstring:lastname];
Nsarray *objects = [[Nsarray alloc] Initwithobjects:
FirstName,
LastName,
FullName,
NIL];
Nsarray *keys = [[Nsarray alloc] Initwithobjects:resultofappendingtwostringsfirststringinfokey, Resultofappendingtwostringssecondstringinfokey, Resultofappendingtwostringsresultstringinfokey,
NIL];
Nsdictionary *userinfo = [[Nsdictionary alloc] initwithobjects:objects Forkeys:keys];
Nsnotification *notificationobject =
[Nsnotification notificationwithname: (NSString *) Resultofappendingtwostringsnotification object:self
Userinfo:userinfo];
[[Nsnotificationcenter Defaultcenter] postnotification:notificationobject];
}
Listener Notification Invocation Method
-(void) appendingisfinished: (nsnotification *) paramnotification
{
NSLog (@ "Notification is received.");
NSLog (@ "Notification object =%@", [Paramnotification object]);
NSLog (@ "Notification user-info Dict =%@", [paramnotification UserInfo]);
}
-(void) viewdidload
{
Monitoring notifications
[[Nsnotificationcenter Defaultcenter]
Addobserver:self
Selector: @selector (appendingisfinished:)
Name: (NSString *) resultofappendingtwostringsnotification object:self];
Send Notifications
[Self broadcastnotification];
}