I’ve got a situation in which I have a class that’s meant to be subclassed, we’ll call it “SuperClass”. This class has a member, we’ll call it “array”. The subclasses of SuperClass will add arrays as members of “array”. SuperClass needs to be able to:
a) know when sub-arrays are being added to “array”, and add itself as an observer to the sub-arrays
b) know when these sub-arrays are being modified (insertions and deletions) and be able to respond accordingly.
Is there a particular way of doing this?
You can use NSNotificationCenter to post a notification every time that a new object is added or deleted.But you need to subclass NSMutableArray.
Make a subclass of NSMutableArray for the main array (the one that contains the sub-arrays), override the inserObject:atIndex method and post a notification which you can call @”subarray inserted” for example.
You need another subclass of NSmutableArray to override insertObject:atIndex and removeObject:atIndex to post a notification with another name.
Tell me if you need an example of code.