Monday, April 29, 2013

NSBundle NSBundleDidLoadNotification example ios

NSBundleDidLoadNotification


NSBundle posts NSBundleDidLoadNotification to notify observers which classes and categories have been dynamically loaded. When a request is made to an NSBundle object for a class (classNamed: or principalClass), the bundle dynamically loads the executable code file that contains the class implementation and all other class definitions contained in the file. After the module is loaded, the bundle posts the NSBundleDidLoadNotification.
The notification object is the NSBundle instance that dynamically loads classes. The userInfodictionary contains an NSLoadedClasses key.
In a typical use of this notification, an object might want to enumerate the userInfo array to check if each loaded class conformed to a certain protocol (say, an protocol for a plug-and-play tool set); if a class does conform, the object would create an instance of that class and add the instance to another NSArray object.
Example of [NSBundle NSBundleDidLoadNotification]
[[NSNotificationCenter defaultCenter] addObserverForName:NSBundleDidLoadNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
    NSLog(@"bundle loaded %@", note);
}];