On 28-May-09, at 12:56 PM, Dave Fernandes wrote:

When the instance variable changes in your custom class, you can call willChangeValueForKey: and didChangeValueForKey: for the entity that contains your custom class.

I haven't ever had to do this, but it is the first thing I would try.

Thanks - you know it's funny I was just trying something like this, and it seems to work - partly.

In the custom entity class I enumerated all the keys in the dictionary ivar (on fetch and insert), adding appropriate observers for each one. This can be used to fire observeValueForKeyPath: in the entity's class, where I tried calling will/didChangeValueForKey: for the persistent representation of the custom class. This caused an infinite loop where these change notifications kept triggering the observer, but I think I'm close.

Maybe I can use the change dictionary in observeValueForKeyPath: to break out of the loop when there's no real change.

Rick


On May 28, 2009, at 12:34 PM, Rick Hoge wrote:


On 28-May-09, at 10:39 AM, Keary Suska wrote:

On May 28, 2009, at 7:03 AM, 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).

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#/ /apple_ref/doc/uid/TP40001919

Thanks - I'd looked at this, and following the information there is what allowed me to insert and display custom object attributes. The documentation shows examples in which an attribute of type NSColor can be set and archived. My problem is that I'm dealing with a complex object type (I have what I think are good reasons for doing this) and I need to flag the context as dirty if an ivar of the custom object is modified.

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.

Hope this clarifies things, and thanks again for the suggestion.

Rick


Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


(43092.6825)

_______________________________________________

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/dave.fernandes%40utoronto.ca

This email sent to dave.fernan...@utoronto.ca


(43092.6825)

_______________________________________________

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