Like the titles says, I want to specify the super of an NSArrayController, something along the lines of self = [super[NSArrayController] function], but have had no luck searching for this. Any ideas? Thanks in advance.
Edited to remove abstract examples as they’re confusing people as to the nature of my question.
The purpose of this is to programmatically do what a simple binding of ‘add’ from an NSArrayController to an NSButton would do in IB. There are several arrayControllers in my application so I want to be able to specify which one I want to obtain the super of by code.
The reason I am looking for the super of an NSArrayController is because I am under the impression that one should address the model rather than the controller (NSArrayController) and my model is a Core Data model that I believe I could get to by using the super of an NSArrayController I specify by name. Perhaps there is a more direct way of adding to the data model.
You’re asking a wrong question.
First, let’s distinguish a class and an instance of the class. Note that there can be, and indeed often are, multiple instances of the same class.
A class
Ccan be a subclass of another classA. ThenAis the superclass ofC. Suppose you have an instancecof the classC. Then, in the implementation of the methods of the classC,selfstands for the instance ofcitself, andsuperstands for the instance ofcas an instance of its superclassA. In a sense, an instance of the classCis also an instance of the classA.Objects can have other relationships than being super or subclasses. For example, a class
Ccan have in its interface an instance variableB* b;In this case, an instancecof the classChas a pointer to an instancebof the classB. In this case,cis not an instance of the classB.The relationship between
NSArrayControllerand the managed object context is one of the latter. An instance ofNSArrayControllercontains a pointer to an instance ofNSManagedObjectContext(moc).So what you want to do is not to get the
superof yourNSArrayController. Instead, you want to get the moc associated to theNSArrayController. Now, how do you get it? To find it out, you open the reference in XCode or on the web at the Apple Developer Connection, see here. Do that right now. Go through the methods. You don’t find one giving you the moc.Then, you go to the top of that page, and follow the superclass of
NSArrayController. See this reference ofNSObjectController. Now, go through the list of the methods. You find-[NSObjectController managedObjectContext], which does the job!In conclusion: if you want the moc associated to the
NSArrayController, you just need to dowhere
arrayControlleris the instance of theNSArrayControlleryou want to deal with. e.g. If you have multiple instances ofNSArrayControllers in the nib, you should have multipleIBOutlets in the app delegate, say,arrayController1,arrayController2, etc. (which are very bad variable names). Then you choose the one you want to deal with.