Just as a quick follow up to another post (http://www.cocos2d-iphone.org/forum/topic/4475) where I showed code that used NSNotification.
For those who are interested - here is some quick info about NSNotification. Have not tested its performance, and it may not be the best method of communicating within you App. But if my current app gets approved - then this will end up in a lot more of my apps.
Basically, a class registers as a notification receiver, and another class sends a notification. Quite simple really. You can do fancy things like filter the notifications - and be specific about who can receive and who can send etc. But basic is good. One thing I found - which was really useful - was the sending of data with the notification. Wonderful.
So to register a notification:
// Place the following line in an INIT or similar method.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendMessage:) name:@"sendMessage" object:nil];
// declare the method in the .h file
-(void)sendMessage:(NSNotification *)notification;
// fill out the message in the .m file
-(void)sendMessage:(NSNotification *)notification
{
NSLog(@"USERINFO:MyUserInfo (its a dictionary):%@",[[notification userInfo] valueForKey:@"1"]);
}
'
In the sending method, prepare the user info and send.
'
NSString * myMessage = [NSString stringWithFormat:@"Message"];
NSDictionary * dict = [NSDictionary dictionaryWithObject:myMessage forKey:@"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"sendMessage" object:self userInfo:dict];
Obviously you can send the message without the data - just remove the userInfo bit in both methods. Really useful for me - but your mileage might vary.
Justin