Re: NSKeyValueChangeNewKey returning NSNull, partially solved

  • > 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

previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today