Crooked Spin

Programming

August 8, 2005

CoreData Tips

I’m going to keep this entry as a running tips/reminders on using CoreData for myself.  i’ll be updating as I come across new things to add.  Please leave comments if you have any cool or informative CD tips to add or if you see that I’m doing something really stupid in one of mine.

  • If an array control has contentSet bound set “Deletes object on remove”.  If it is not set, the object will not be removed from the store.  It will only be removed from the controller and will reappear next time the controller is populated.
  • Objects have to be manually assigned to a store after they are created.  So if you have an xml or SQL store and an in memory store for the library and smart groups you need to call
    - (void)assignObject:(id)object toPersistentStore:(id)store on each new object or you’ll get an error at the next save saying to can’t save an object once it has been saved to a different store.

    My solution to the problem was to make a method called
    - (void)assignInsertedObjectsToPrimaryStorethat calls
    - (NSSet *)insertedObjects on the moc and then enumerates over each object in the set adding it to the SQL store.  This is done after any of the user events that adds an occurs.

    You could also simply assign the object to the correct store right after it is created.  In my case the user created object creates a couple dozen dependent objects that all have to be assigned, so I found the above method to be the easiest solution.

  • SQL stores may not like transient attributes in abstract entities.  I’m not 100% sure yet if that combo is what made the error I was encountering. Turning off the transient flag fixed the issue though.  It also did no occur when I was using an XML store during development.

More to come as I come across more items.  I should have started this right away.  I know I’m forgetting a couple items.

Leave a comment

RSS feed for comments on this post. TrackBack URL

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>