• 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
Re: CoreData Best Practices
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData Best Practices


  • Subject: Re: CoreData Best Practices
  • From: Bill Bumgarner <email@hidden>
  • Date: Fri, 29 Apr 2005 15:00:03 -0700

On Apr 29, 2005, at 1:34 PM, James Clause wrote:
I'd like some advice on the best way to use CoreData in various
situations.  I'm trying to create a BibTeX manager.  The problem I'm
facing is that BibTeX allows user defined fields and multiple
authors.  The obvious way to handle this is to store multiple authors
as an NSArray of NSStrings and the user defined fields in an
NSDictionary.  However, these type aren't available as attributes in
CoreData.  The best way I can think of to overcome this is to
serialize dictionaries and arrays and store them as data attributes.
This doesn't seem to be a solution and I wondered if anyone else had
a better one.

To store the authors:

Create an Author entity in your Core Data model and create a relationship between your existing entity and the Author entity. Create new Author entity instances, as needed, and relate them to your -- for lack of a better term -- Paper entity, as needed. If you are managing multiple Papers, it is likely that any one Author may be an author of multiple Papers and, therefore, you should use a fetch specification to grab an existing Author, if present, and relate that existing Author instead of creating duplicate Authors.

With a reverse relationship from Author -> Paper, you could then ask an Author for all of its Papers. Core Data will take care of managing the inverse relationships automatically.

To store the key/value pairs:

Create a KeyValuePair entity that contains a 'key' attribute and a 'value' attribute. Then, create instances of those key/value pairs and relate them to your Paper entities, as necessary.

Alternatively, you could store the values in a attribute marked as Binary, then use a derived attribute to archive/unarchive the dictionary/array into/out-of that attribute. This is suboptimal for a number of reasons and not really recommended, but can be useful in certain circumstances.

---

In general, when creating the data model for your application, consider using managed objects for any place that you think you might need an NSArray or NSDictionary. An NSArray implies a relationship. NSDictionary implies an alternative form of data storage and is not hard to push into Core Data.

b.bum
_______________________________________________
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: CoreData Best Practices
      • From: John Timmer <email@hidden>
References: 
 >Re: CoreData Best Practices (From: John Timmer <email@hidden>)

  • Prev by Date: SQLite command line tool compat with Core Data?
  • Next by Date: Re: SQLite command line tool compat with Core Data?
  • Previous by thread: Re: CoreData Best Practices
  • Next by thread: Re: CoreData Best Practices
  • Index(es):
    • Date
    • Thread