Search code examples
iosobjective-ccocoa-touchobserver-patternnsnotificationcenter

Downside to multiple instances of NSNotifcationCenter in cocoa touch


I'm looking into implementing the observer design pattern in cocoa touch, and have discovered that Apple has the cool NSNotificationCenter object that seems like it'll do exactly what I'm looking for. However, most of the tutorials I've seen for this have only one or two instances of an NSNotificationCenter running.

Because of the lack of tutorials using this practice, I'm wondering: Is there any downside to having an NSNotificationCenter instance on each model I want observed? (in my specific case it'll be about 16 models). Or is there a way for to tell a view to observe only a specific model, using one global instance of an NSNotificationCenter?


Solution

  • You can use the 'object' parameter of the NSNotificationCenter methods to get this effect without allocating one per object.