Maintaining mutable values with NSDictionaryControllerKeyValuePair
Maintaining mutable values with NSDictionaryControllerKeyValuePair
- Subject: Maintaining mutable values with NSDictionaryControllerKeyValuePair
- From: Simone Manganelli <email@hidden>
- Date: Sat, 27 Dec 2008 03:05:58 -0800
I'm using an NSDictionaryController object to control the data
provided to an NSTableView object. I'm attempting to use key-value
coding through the dictionary controller to manipulate the data in a
bindings-compatible way, by calling the method -arrangedObjects on the
NSDictionaryController, and then manipulating the
NSDictionaryControllerKeyValuePairs that this method returns in an
array.
The problem is that my values for the objects that -arrangedObjects
returns also need to be mutable dictionaries themselves. That is, my
NSDictionaryControllerKeyValuePairs look like this:
key: someKey
value: NSMutableDictionary
key: someKey1 value: someString1
key: someKey2 value: someString2
If I attempt to set the values within the NSMutableDictionary directly
via key-value coding on a completely new object, by calling -
setValue:forKeyPath:@"value.someKey1", I get errors saying that this
class isn't KVC compliant for the key someKey1 (presumably because the
KeyValuePair doesn't automatically know that I want to create an
NSMutableDictionary as the value).
So I'm left with manually creating the NSMutableDictionary value
(which is fine), and then calling setValue: on the KeyValuePair. The
problem is, even if I use an NSMutableDictionary as the value, the
KeyValuePair seems to set it with an immutable value instead
(NSDictionary, rather than NSMutableDictionary). I can see this
because if I then call setValue:forKeyPath:@"value.someKey1", I get an
error saying I'm sending a mutable method to an immutable object. But
I'm stuck, because I can't later set an entirely different
NSMutableDictionary value to the KeyValuePair if I have my table
observing someString1 or someString2, because that violates KVO.
How do I get around this problem? Is there a way to tell
NSDictionaryControllerKeyValuePair to preserve the mutability of the
values that I'm setting? It seems that it might have internal copy
semantics when setting the value rather than retain semantics, which
would cause the problems I'm seeing.
I hope that all made sense. Any help would be greatly appreciated.
Thanks!
-- Simone Manganelli
_______________________________________________
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