In an OS X app, I wanted to bind a table of objects, each represented by a 
dictionary, to an array of dictionaries in user defaults.

So I bound the Content Array of the array controller to the 'values' of the 
shared user defaults controller with an arbitrary key path, which pleasantly 
became the key to the array in the user defaults.  I set "Handles Content as 
Compound Values” to ON.

Result: The table is populated as expected from user defaults when its window 
opens, and all works and persists as expected if user adds or deletes an object 
(row).  But changes to object attributes are persisted only for new objects, 
and only if user adds *another* object before quitting.

In the array controller's content, the object attribute is always changed as 
expected.  So, the problem is the binding of the array controller content to 
user defaults, and I think the explanation is that, as always, KVO is 
“shallow”.  Observing an array does not observe changes to its elements.

I’m disapointed that the “magic of Cocoa Bindings” does not seem to provide a 
simple “code-less” solution to this simple requirement.  Did I miss something?

Jerry

I also tried this using a custom object instead of an NSMutableDictionary as 
the content class of the array controller, making my custom class conform to 
NSCoding, and inserting a NSKeyedUnarchiveFromData value transformer into the 
binding.  Result: Exactly the same deficiency.


_______________________________________________

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

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

Reply via email to