Understanding NSArrayController


#1

When I drag the NSArrayController object (from Cocoa->Objects and Controllers) into the Editor area and set its class to Person-----am I subclassing NSArrayController?
If it is not subclassing NSArrayController then how is it subclassed?
If it is subclassing NSArrayController, then how do I override its add: method so as to customise it to suite my needs?
Thanks.


#2

[quote=“rounak”]When I drag the NSArrayController object (from Cocoa->Objects and Controllers) into the Editor area and set its class to Person-----am I subclassing NSArrayController?
If it is not subclassing NSArrayController then how is it subclassed?
If it is subclassing NSArrayController, then how do I override its add: method so as to customise it to suite my needs?
Thanks.[/quote]
What do you mean by “set its class to Person”?

The Class Name attribute under Object Controller in Attributes Inspector or its Class under Custom Class in Identity Inspector?

If you are just setting the Class Name attribute under Object Controller, you are not subclassing it. However if you are setting its Class to Person under Custom Class you are indicating that you want to subclass it

But if you are subclassing it, you should choose a better name, say PersonArrayController:

@interface PersonArrayController: NSArrayController
...
@end

This would be very confusing:

@interface Person: NSArrayController
...
@end

See: NSArrayController Companion guides

  • Cocoa Bindings Programming Topics
  • Predicate Programming Guide
  • Core Data Programming Guide

#3

What does setting the Class Name attribute under Object Controller do?


#4

ok…found the relevant text in the documentation:

[quote]Specifying the Class of a Controller’s Content

In order for a controller to create new content objects automatically or in response to the target-action methods, it must know the appropriate class to use.

Controllers can be configured in one of two modes: object mode or entity mode. In object mode the content class is specified by the method setObjectClass: or in the controller inspector panel in Interface Builder. If the controller is configured in entity mode, the class is determined by the name of the entity or by the relationship that the entity defines for the key. The entity name is set using setEntityName: or in the controller inspector panel in Interface Builder.

If the controller is in object mode, the method newObject is used to create new objects. The default implementation simply allocates a new object of the class specified by objectClass or the entityName and sends the object a standard init message with no arguments. If your content objects require more complex initialization, you can subclass the appropriate controller class and override the newObject method.

An NSObjectController expects the content object to be of the class specified by the object class or entity name. When using the NSArrayController and NSTreeController the object class refers to the individual content objects, rather than the collection that holds the objects. In both cases the collections are expected to be key-value-coding compatible with arrays or sets, depending on the binding providing the content for the controller.[/quote]