Nsarraycontroller selection not updating

After implementing this code the initial (and subsequent) sorts work as intended. With a highly subclassed NSArray Controller and a modification to your Core Data managed object you should be able to provide user defined order for a specified object.

IMO this is a major pain and it would be nice to see some kind of official support for this type of (fairly common) behavior.

Instead the data just gets displayed in the natural order as retrieved by Core Data, which may not always be the same and certainly won’t be what the user intended. NSArray Controller sorts its contents (arranged Objects) via a defined NSSort Descriptor which will sort your KVO compliant data object based upon a specified key.

There is a way around this problem but it isn’t exactly pretty and it undoubtedly is not drag and drop simple. Witness the awake From Nib method of our NSArray Controller subclass: Of course, this NSSort Descriptor could be set externally to the controller.

Do you ever find you need to pre-populate an i OS Core Data app with some data and wanted to create and edit that data with a full OS X desktop app?

If you have only ever developed for i OS you may not consider this approach because OS X seems at first to be more complicated.

At first this issue took a bit of hunting to track down but, after reading the Core Data docs it becomes somewhat obvious.

NSSort Descriptor will access its defined key attribute for the data object via KVC.In order to resolve/work around this issue more NSArray Controller subclassing is needed: Basically, this code is straight out of the Core Data docs.In order to force the fault data to be loaded we’re retrieving all objects in the controller and forcing the full data to be loaded via the message ‘set Returns Objects As Faults: NO’ (OS X 10.5 only).(There is also be an OS X unit test target created by default but I will remove that for now).It is interesting to take a look at the objects in the storyboard created by the Xcode template to get a feel for the architecture of a modern OS X application: Application Object (NSApplication): Like the object of an i OS application you do not normally subclass this object instead you work with the application delegate.A typical use case for this scenario would be when using a source list such as the one found in the navigation pane of i Tunes.

You must have an account to comment. Please register or login here!