Re: NSDictionary setValue KVO
Re: NSDictionary setValue KVO
- Subject: Re: NSDictionary setValue KVO
- From: Ken Thomases <email@hidden>
- Date: Sun, 10 Oct 2010 14:57:41 -0500
On Oct 10, 2010, at 10:32 AM, Keary Suska wrote:
> On Oct 10, 2010, at 5:54 AM, Trygve Inda wrote:
>
>> I have a nib with an NSArrayController bound to this object with a keypath
>> of myDict.@allValues
>>
>> This works, but when I want to add an item to the dict (and have it
>> reflected in the arraycontroller), the method in my object is:
>>
>> [self willChangeValueForKey:@"myDict"];
>>
>> NSDictionary* test =
>> [NSDictionary dictionaryWithObjectsAndKeys:@"someValue", @"someKey", nil];
>>
>> [myDict setValue:test forKey:@"someOtherKey"];
>>
>> [self didChangeValueForKey:@"myDict"];
>>
>>
>> This works too, but how can I do this without the willChange/didChange ?
>>
>> Shoudln't the setValue call, fire a KVO message?
>
> NSDictionary does not emit any notices when the collection itself is mutated, or when keys change. Have you tried using an NSDictionaryController instead?
This is not true. I have made that mistake myself, but NSMutableDictionary is KVO compliant for its keys (qua properties). The open questions are a) whether it emits a change notification for allValues, and b) what the heck "myDict.@allValues" is supposed to mean. I'm not aware of that being a valid KVC collection operator.
A quick test program on Snow Leopard: a) confirms that NSMutableDictionary sends out change notifications for its keys, but b) does not send out change notifications for the allValues property.
Regards,
Ken
Attachment:
Untitled.m
Description: Binary data
_______________________________________________
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