Re: Binding an Array of Dictionaries
Re: Binding an Array of Dictionaries
- Subject: Re: Binding an Array of Dictionaries
- From: Keary Suska <email@hidden>
- Date: Sat, 12 Dec 2009 09:48:11 -0700
On Dec 11, 2009, at 10:36 PM, Gerriet M. Denkmann wrote:
> realContent (which contains the NSDictionary).
>
> And now I can bind the content of the NSDictionaryController to NSArrayController selection.realContent and everything works perfectly - changes done in the TableView of my Dictionary automatically get inserted into my Array.
>
> Question: Is this really a very clever idea - or (as I am about to find out later) an awfully silly one?
It is an awfully silly one. Are you sure that you really need an NSDictiorary to represent your data? I.e., do the keys vary widely across the different items in your array?
> And what about another idea I had:
> Replace the NSArray (a0, a1, ..., an ) with an NSDictionary: ( 0 → a0, 1 → a1, ..., n → an )?
> I have not tried this yet, but it sounds a plausible workaround. Or is it?
The issue isn't the array, the issue is the proxy object returned by "selection". You will have the same issue regardless of the enclosing object.
Using bindings & KVO, tracking the selected object is trivial. It could have been coded in the time it took to write these emails.
E.g:
0. Object that owns the array has an outlet or some other reference to the array controller
1. Said object has a method, say -currentDictionary, that returns a proper value from the array controller's selectedObejcts method
2. Object observes array controllers selectedObjects
3. In the observe callback, after checking the key in question, object calls willChange/DidChange for "currentDictionary"
4. NSDictionaryController is bound to object, key path "currentDictionary".
OTOH, that's it.
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