Re: Bind NSTableView to array of dictionaries in user defaults
Re: Bind NSTableView to array of dictionaries in user defaults
- Subject: Re: Bind NSTableView to array of dictionaries in user defaults
- From: Keary Suska <email@hidden>
- Date: Thu, 05 May 2016 14:47:03 -0600
> On May 5, 2016, at 7:44 AM, Jerry Krinock <email@hidden> wrote:
>
> 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.
Is this a single or multi-level keypath? IIRC the issues Quincy is referring to are common in a multiple-object keypath, especially for defaults as NSUserDefaultsController uses some internal trickery to edit the immutable collections maintained by NSUserDefaults.
> 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.
I cannot replicate this behavior with a straightforward approach. Can you create a reduction that replicates the behavior?
> 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.
This is curious—how do you know that the attribute is being changed as expected? Is it that it shows in the UI, but is not persisted? Have you changed the default value of -[NSUserDefaultsController appliesImmediately]?
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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