6/03/2009

MVC, Singleton, Delegate, NSNotificationCenter

It's hard to come up with a correct design pattern for you program. One of the useful one is NSNotificationCenter where you can access a selector from anywhere in your code.

プログラミングのデザインパターンをうまく構成するのはなかなか難しい。そこで一つ使えるのがNSNotificationCenter。使い過ぎは要注意。

Create a notification:


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:@"myNotification" object:nil];


Call it from anywhere in your code:


[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:nil userInfo:nil];

No comments:

Post a Comment