Weird KVO problem

  • Sorry for all the KVC/KVO/KVB postings lately, but I'm finding it hard
    to understand their behavior. Here is my latest problem (don't even
    ask me how I got here; most of this code is the result of a desperate
    attempt to figure all this out):

    - (void) ping
    {
    NSLog( @"selection:%@", [_blogAccountsController
      valueForKeyPath:@"selection.serviceURL"] ) ;
    }

    - (void) awakeFromNib
    {
    [_blogAccountsController addObserver:self
      forKeyPath:@"selection.serviceURL"
      options:0 context:nil] ;

    //    observeValueForKeyPath:ofObject:change:context: is only ever called
    //    if the following two lines are uncommented.
    //    [self    performSelector:@selector(ping)
    //        withObject:nil afterDelay:0] ;

    }

    - (void)observeValueForKeyPath:(NSString *)keyPath
      ofObject:(id)object
      change:(NSDictionary *)change
      context:(void *)context
    {
    NSLog( @"attr at keyPath changed: %@ on object: %@" , keyPath ,
    object ) ;
    }

    _blogAccountsController is an NSArrayController bound to a Core Data
    context to an entity named "blog" which in turn contains a serviceURL
    attribute.

    Without the performSelector:withObject:afterDelay: message in -
    awakeFromNib, my observeValueForKeyPath is never called. However, if I
    uncomment those lines, observeValueForKeyPath is called just fine.

    What's going on here?

    Thanks,

    Mike
previous month november 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    
Go to today