Re: When NSArray is not an Array
Re: When NSArray is not an Array
- Subject: Re: When NSArray is not an Array
- From: "I. Savant" <email@hidden>
- Date: Thu, 11 Jan 2007 15:41:19 -0500
Gordon:
What is it with database designers and specifically Core Data
that they
don't understand the concept of an array, the definition of which
is an
ORDERED set? NSArray (NSMutableArray) are arrays, not sets -- that
is,
until you try to use Core Data. Like any typical relational
database, the
concept of order goes totally out the window.
How is this any different than a relational database? If you want
to have an arbitrary sort order for your records, you still have to
have *some* key on which to sort the results of the query. You still
have to update the keys of the relevant records you wish to reorder.
Our application has many layers of lists (i.e., ordered sets,
arrays,
whatever): Lists of sessions which are lists of segments which are
lists of
screens which are lists of layers which are list of draw objects
which are
lists of attributes which could be lists of grouped objects, etc.
ORDER is
all important.
Yes, many of us have the same requirements ... and the solution
has been covered in detail on this list a number of times.
The only way around this seems to be to add an integer index
field that
has to be re-sequenced every time there is an edit that affects the
list.
It's a pain just to re-do what NSMutableArray and NSArrayController
are
supposed to do already. A search of the cocoa-dev list showed a
lot of
chatter on this subject -- too much to peruse. Has there been any
progress
on ordered list with CoreData? Any other workarounds?
With respect, it's nobody else's problem if you aren't motivated
enough to read through the search results you produced -- there
aren't that many in this instance, either. Had you read just a few
of, you would've seen that, in its current incarnation, a sort order
key or the use of a linked list are the only solutions to this
limitation of Core Data. I prefer the use of a sortOrder key ... it's
cleaner and easier to maintain in my opinion and experience. YMMV.
That said, it really isn't *that* complicated to create a generic,
reusable NSArrayController subclass that updates the sortOrder key
(along with implementing drag and drop, etc.). The drag-reorder part
is done for you in several examples on the "Internets" (google "mmalc
bindings example" and you'll find a ready-made example) and the
reordering code is easy to add to that.
--
I.S.
_______________________________________________
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