• 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: Unique items in Core Data models
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unique items in Core Data models


  • Subject: Re: Unique items in Core Data models
  • From: "John R. Timmer" <email@hidden>
  • Date: Fri, 18 May 2007 08:58:54 -0400

Managed objects already have a unique ID -- the objectID.
The issue is, how do you subsequently ensure uniqueness of a particular attribute...

Came in late to the discussion, and don't know whether this has been suggested...


I solved this by creating a singleton, non-managed object. When i hand it a ManagedObjectContext, it fetches all the appropriate objects into an array, traverses the key path to create an array of the appropriate attribute, and then makes that array into a set (since that's faster for object presence tests). It registers with the ManagedObjectContext for new object creations and attribute changes, and updates the set accordingly.

It has a method to check the set for any key you want to add, which i use during validations of keys. I thought it was a nice way to clump all the relevant code in a single class, and since entity names and keys are strings, it's easy to generalize the code so you can configure the singleton differently in different projects. I don't think there's any way to speed up updating the set, but if you find the presence test slow, you can change it to an all-C function, treating the set as a CFSet.

JT

____________________________________
Science Writer
Ars Technica - http://arstechnica.com/journals/science.ars
Wellcome Science - http://www.wellcome.ac.uk/wellcomescience



_______________________________________________

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


References: 
 >Unique items in Core Data models (From: Keith Penrod <email@hidden>)
 >Re: Unique items in Core Data models (From: Diederik Hoogenboom <email@hidden>)
 >Re: Unique items in Core Data models (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: Unique items in Core Data models
  • Next by Date: Re: Fill text in a circle path - NSVIEW
  • Previous by thread: Re: Unique items in Core Data models
  • Next by thread: NSWindowController showWindow
  • Index(es):
    • Date
    • Thread