• 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: Triggering change notifications when modifying custom object ivars in core data app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Triggering change notifications when modifying custom object ivars in core data app


  • Subject: Re: Triggering change notifications when modifying custom object ivars in core data app
  • From: Rick Hoge <email@hidden>
  • Date: Thu, 28 May 2009 16:17:57 -0400


Just a follow-up. It's not perfect, and I'll revisit the design, but it does what I need for now.


Specifically my entity has a 'transformable' attribute for which the
values are a custom object class, and this object class has an ivar
that is an NSMutableDictionary.  The user can modify entries in this
dictionary, and I would like this to cause the context to be flagged
as dirty and to have the custom object flagged to be updated in the
persistent store.

I got this all to work the way I need using the following strategy:

1) I used the dual representation (transient object + persistent transformable data) for my custom object attribute, as described in the Core Data docs on Non-Standard Persistent Attributes.

2) When the entity is fetched I create the transient object representation from the persistent data attribute. When the entity is fetched or inserted I add an observer for every entry in the dictionary of the custom object.

3) If one of the observers is triggered, I invoke will/ didChangeValueForKey: for the persistent data attribute. This causes the context to be flagged as dirty if a dictionary entry is changed.

4) I implement -willSave in the entity's class, and here assign the persistent data attribute as shown in the Core Data doc example for the "Delayed-Update Set Accessor". This assignment causes the data to be rewritten to the disk store. The objects themselves are pretty light-weight, so the fact that they will be re-written on every save is not a huge deal.

This is a relatively small part of the whole app, so I can live for now with the fact that changes to these dictionary entries won't benefit from undo/redo. In fact the objects in question are shared with a number of other apps that don't have undo/redo, so this will not be too shocking to the users (although it would have been nice).






_______________________________________________

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


References: 
 >re: Re: Triggering change notifications when modifying custom object ivars in core data app (From: Ben Trumbull <email@hidden>)
 >Re: Triggering change notifications when modifying custom object ivars in core data app (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: How to activate Find and Replace for Textview?
  • Next by Date: Re: Triggering change notifications when modifying custom object ivars in core data app
  • Previous by thread: Re: Triggering change notifications when modifying custom object ivars in core data app
  • Next by thread: Re: Triggering change notifications when modifying custom object ivars in core data app
  • Index(es):
    • Date
    • Thread