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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to