Multiple Delegates on a Singleton Object

Hi everyone,


I have a singleton object in my application (a ServerAccess class which represents functions/properties pertaining to my app server). This class uses a protocol (ServerAccessDelegate) for some communication.


If I do this:


server.sharedInstance.delegate = self;


It works fine, but it can only work with a single class. If I have two classes that are both subscribed to the ServerAccessDelegate, then only the most recent class to call delegate = self actually gets these delegate methods called, since it is a single 'delegate' variable.


Right now, I have solved this issue by simply using an array to store references to the ServerAccess delegates, and an addDelegate function so multiple classes can receive these delegate function calls. It works fine, but I was wondering does anyone know of a more elegant solution to this problem? My current solution feels very dirty.


Thanks!

- Brad

The array is one way to do it. Another option is to use NSNotifications.


On OS X it is more common for both (a delegate and notifications) to be used...for example you can get callbacks given to NSWindowDelegate without setting yourself as the window's delegate property by becoming an observer for whatever events you want.

Multiple Delegates on a Singleton Object
 
 
Q