• 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: Quincey Morris <email@hidden>
  • Date: Thu, 28 May 2009 11:16:56 -0700

On May 28, 2009, at 06:03, Rick Hoge wrote:

I have a core data (doc-based) app in which one of the entities includes a custom object as a persistent attribute. The custom object class implements NSCoding, and these objects are saved to the core data store with no problem (they are read back correctly etc). Instance variables of the custom object are exposed in the user interface, and can be edited by the user.

The problem I have is that changes to instance variables of these custom objects are not reported to the managed object context, so the core data document is not flagged as dirty and, even if I force a save by adding an entity and invoking save, the modified custom object is not saved (if I quit and reload the old ivar values are loaded).

Well, yeah. The problem is that you're using something with the behavior of an entity (your custom object) as an attribute. That is, you want your object graph to include your custom objects (for the purpose of monitoring their changes), but you haven't implemented your data model that way. Typically, Core Data *attributes* are immutable (like NSNumber or NSString) for exactly that reason. The mutability of your custom object suggests that it should be an entity, not an attribute. [Sorry, not sure if that's clear. I'm trying to say the same thing 3 different ways.]


Is there a reason you can't make your custom object a Core Data entity, and expose its properties (the troublesome instance variables) as attributes of that entity?

It's not impossible that the willChange/didChange approach can be made to work, but this sort of thing tends to really crap out in the face of undo. Consider what happens when you change an instance variable of a custom object, if the object is already in the undo history from a previous change. Suddenly, undoing changes ... won't.


_______________________________________________

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


  • Follow-Ups:
    • Re: Triggering change notifications when modifying custom object ivars in core data app
      • From: Dave Fernandes <email@hidden>
References: 
 >Triggering change notifications when modifying custom object ivars in core data app (From: Rick Hoge <email@hidden>)

  • Prev by Date: How to get the selected popupmenu item with core data
  • Next by Date: re: 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