Re: One Solution for storing ordered arrays within Core Data objects
Re: One Solution for storing ordered arrays within Core Data objects
- Subject: Re: One Solution for storing ordered arrays within Core Data objects
- From: SA Dev <email@hidden>
- Date: Mon, 13 Jun 2005 08:25:42 -0400
Fletcher:
Kudos for the novel approach, but I wonder if this might cause
performance problems in other situations. Adding an extra property
called "sortOrder" or whatever you like as a number will give you
sorting for free, using Bindings. Drag and drop (or some other user
action) would cause all the objects to be renumbered.
Can anybody (who knows better than I do) state with authority
which would be the better performer?
On Jun 12, 2005, at 5:32 PM, Fletcher T. Penney wrote:
One problem that has been raised on this list and in other places
is the fact that Core Data doesn't store ordered arrays of objects,
but rather unordered sets of objects. This can be a significant
limitation in certain contexts.
In other words, if you are creating an application storing
information about journal articles, you can't simply store the list
of authors and expect the order to be preserved (the order of
authors is important to keep). Each time you loaded the data, the
order of the authors would be random, which would cause problems in
academic situations.
I have found a rather simple solution to this problem (for simple
strings anyway).
I stored the authors as a single string attribute within my Core
Data model, with each author separated by a newline. For example:
Smith, John
Doe, Jane
Johnson, Roy
I then wrote a StringToArray ValueTransformer that separates that
single string into an array of strings, one per author. This can
be used as the content for an array controller and used in whatever
means you like. The reverse transformer then converts the array
back into a single string for storage in the Core Data file.
Obviously, this exact solution would not work for complex pieces of
data, but it is handy for many situations.
To see an example, check out http://fletcher.freeshell.org/wiki/
FilteringWithCoreData and experiment with the interests table.
The code is released under the GPL - hope it helps somebody. (And
yes, I do need to modify my source files to indicate this fact -
just haven't gotten around to it)
As always, please feel free to contact me with questions,
suggestions, etc.
Fletcher
--
Fletcher T. Penney
email@hidden
I drink to make other people interesting.
- George Jean Nathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40silentalcove.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden