I am looking at a project which was provided me by my organization, for study.
The problem is that in this project I found some code which I never saw before.
Please tell me why the following code is written.
-(void)notifications
{
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector(hideViews) name: @"Hide" object:nil];
}
This problem arose because this project has only some code for designing.
Sorry if this is a silly question…
You should read up on how notifications work in Cocoa. Consult Apple’s documentation for more information: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html
Basically,
NSNotificationCenteris a class that broadcastsNSNotificationsfrom one object to potentially many observing objects. One object can post a notificationand other objects can listen for this notification.
Then, when the first object posts the notification,
NSNotificationCenterwill notify the other observing object, andnotificationHandler:gets called.