Re: Core Data, to-many relationships, and object graph consistency
Re: Core Data, to-many relationships, and object graph consistency
- Subject: Re: Core Data, to-many relationships, and object graph consistency
- From: Quincey Morris <email@hidden>
- Date: Mon, 15 Jun 2009 10:58:11 -0700
On Jun 15, 2009, at 06:43, Sebastian Celis wrote:
I believe I found my issue. In my SCBook class I was overriding
didChangeValueForKey:withSetMutation:usingObjects: so that I could
store an NSString containing a comma-separated list of tags associated
with the book. Apparently this is a very bad way to do it. I missed
the big warning in the documentation which states that this method
should not be overridden. What is the correct way to do this from
inside of the SCBook class?
If the comma-separated list is just for display in the user interface,
you could generate it on the fly. Use
'keyPathsForValuesAffectingTagList' (or whatever) to ensure that the
proper KVO notifications get sent when the underlying bookTag objects
change.
If you really want to store the comma-separated list, you can write
your own set accessor overrides (addTagsObject, removeTagsObject,
addTags, removeTags) and rebuild the string in the accessors. The only
trick here (apart from following the documented pattern for writing
the accessors) is to realize that the accessors are also called at
undo time, so accessors with a side effect of updating a different
property can be problematical unless you're careful.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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