KVO for property of a different class

I would like to add an observer to my UIViewController for a property in my application sub.

is it possible like below code?

myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate]                                         ;


    [self addObserver:self
           forKeyPath:appDelegate.currentLocation
              options:0
              context:nil];

      

the problem is expecting the value for "forKeyPath" to be NSString.

+3


source to share


1 answer


myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate]                                        ;

[appDelegate addObserver:self
              forKeyPath:@"currentLocation"
                 options:0
                 context:nil];

      



+6


source







All Articles