Re: NSKeyValueChangeNewKey returning NSNull, partially solved
Re: NSKeyValueChangeNewKey returning NSNull, partially solved
- Subject: Re: NSKeyValueChangeNewKey returning NSNull, partially solved
- From: Kai Brüning <email@hidden>
- Date: Mon, 24 Dec 2007 11:14:17 +0100
>have you considered implementing manual KVO notifications for the setter?
I did consider it, but didn't try it (yet) because I *am* getting the changed notification, just with an - in my opinion - incorrect change dictionary.
But I at least partially solved the problem in the meantime: the observed class (class of objectToObserve below) was based upon NSController. When I change this to NSObject, everything works.
I guess that NSController modifies automatic KVC/KVO in some way. I did not find anything in that direction in the docs so far, but that of course does not mean that it is not documented somewhere. I'll check whether NSController overrides any of the KVC/KVO control methods when I find the time.
Nevertheless, a word by somebody in the know would be appreciated.
Happy Christmas
Kai
>
>
>
>On Dec 22, 2007, at 12:57 PM, Kai Brüning wrote:
>
>>Mike:
>>
>>I am aware of this, but have no idea why nil should be returned in my case.
>>
>>Best,
>>Kai
>>
>>>NSNull is used by KVO to represent a nil value.
>>>
>>>Mike.
>>>
>>>On 21 Dec 2007, at 18:50, Kai Brüning wrote:
>>>
>>>>Hi,
>>>>
>>>>I have a case in which a KVO change dictionary always contains NSNull under NSKeyValueChangeNewKey and no idea why.
>>>>
>>>>Observation is established like this:
>>>>
>>>> [objectToObserve addObserver:self forKeyPath:@"visiblePage"
>>>> options:NSKeyValueObservingOptionNew
>>>> context:whatever];
>>>>
>>>>objectToObserve has this pair of accessors:
>>>>
>>>>- (NSNumber*) visiblePage {
>>>>return [NSNumber numberWithInt:_visiblePage];
>>>>}
>>>>
>>>>- (void) setVisiblePage:(NSNumber*)value {
>>>>_visiblePage = [value intValue];
>>>>}
>>>>
>>>>which are declared in the interface, too:
>>>>
>>>>- (NSNumber*) visiblePage;
>>>>- (void) setVisiblePage:(NSNumber*)value;
>>>>
>>>>_visiblePage is an iVar of type int.
>>>>
>>>>Any idea why the change dictionary would contain NSNull for NSKeyValueChangeNewKey in this case?
>>>>Note: - (NSNumber*) visiblePage is not called during the whole change process, but observeValueForKeyPath:ofObject:change:context: is called on the observing object, just with the defective change dictionary.
>>>>
>>>>In a very similar case (identical observed class, slightly different observer) everything works well.
>>>>
>>>>The workaround is obvious (using valueForKey: instead of depending on the change dictionary) and works, but I'd would prefer to understand this issue.
>>>>
>>>>This is all with Xcode 3 under 10.5.1 with GC off.
>>>>
>>>>Best,
>>>>Kai
>>>>_______________________________________________
>>>>
>>>>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
>>
>>_______________________________________________
>>
>>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
_______________________________________________
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