Re: NSArrayController, saving and reloading sort descriptors
Re: NSArrayController, saving and reloading sort descriptors
- Subject: Re: NSArrayController, saving and reloading sort descriptors
- From: Aurélien Hugelé <email@hidden>
- Date: Wed, 14 Mar 2007 16:40:28 +0100
Knud,
I think that the reason is quite simple:
when you sort by clicking on a table column, the sort is performed IN
MEMORY using cocoa sort, that is KVC compatible, and calls your
anyLabel method, and the sort descriptor is set on the array controller.
Then this sort descriptor is stored to user default and you relaunch
the app, when the array controller get its awakeFromNib when loaded
from the nib, a delayed fetch is performed to fillup the content of
the array controller. In order to optimize the loading, apple decided
to use the fetch to get AND SORT the data in a single batch. The
problem is that when you add a sort descriptor (in that case the one
from the user default) to a fetch, the sorting is done by SQLite (if
you have a SQL store), and thus the key must be hardcoded as an
attribute in database to be accessible/known by SQLite... KVC won't
work here...
You can customize you array controller to change the sort descriptor
on the fly when the fetch is executed so that it does not sort with
SQLite backend, then set the sort descriptor once the fetch has been
execcuted to perform the sorting in memory, the cocoa way...
Seems a little complicated huh?
On 14 mars 07, at 15:00, Knud Hinnerk Möller wrote:
Hi,
can anyone help me with the following problem:
- I have an NSArrayController for a subclass of NSManagedObject
called KNResourceNode
- KNResourceNode has a fake access method "anyLabel" (i.e. not
giving access to any real ivar or attribute)
- in IB I specify the sort descriptor for a table column that is
bound to the controller as such: (key: "anyLabel", selector:
caseInsensitiveCompare, order: ascending) - this works fine
- when the application terminates, I write the controller's sort
descriptors to NSUserDefaults
- I bind the controllers sort descriptors to NSUserDefaults (so
that the sorting is remembered)
Now, this all works fine when I specify a particular contentSet
binding for the controller. When I don't (i.e. I just want all
instances of KNResourceNode), I get the following error on startup
(when then binding is taking place, I suppose) - but only for sort
descriptors that use "anyLabel"! Not for any other keys, which
might be actual attributes of KNResourceNode.
*** NSRunLoop ignoring exception 'Unknown key in query. anyLabel'
that raised during posting of delayed perform with target 376330
and selector 'invokeWithTarget:'
I hope I explained this well enough. Does anyone know what is going
on here?
Cheers,
Knud
-------------------------------------------------
Knud Möller, MA
+353 - 91 - 495086
Digital Enterprise Research Institute
National University of Ireland, Galway
Institiúid Taighde na Fiontraíochta Digití
Ollscoil na hÉireann, Gaillimh
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40gumitech.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden