• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
One Solution for storing ordered arrays within Core Data objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

One Solution for storing ordered arrays within Core Data objects


  • Subject: One Solution for storing ordered arrays within Core Data objects
  • From: "Fletcher T. Penney" <email@hidden>
  • Date: Sun, 12 Jun 2005 17:32:08 -0400

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


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

  • Follow-Ups:
    • Re: One Solution for storing ordered arrays within Core Data objects
      • From: Chris Hanson <email@hidden>
    • Re: One Solution for storing ordered arrays within Core Data objects
      • From: SA Dev <email@hidden>
  • Prev by Date: menu question
  • Next by Date: Re: how to make an NSWindow unmovable...
  • Previous by thread: Re: menu question
  • Next by thread: Re: One Solution for storing ordered arrays within Core Data objects
  • Index(es):
    • Date
    • Thread