user836026
user836026

Reputation: 11340

KVO for property of another class

I would like to add observer in my UIViewController for property in my application delegate.

is it possible like below code?

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


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

the issue it expect the value for "forKeyPath" to be NSString.

Upvotes: 3

Views: 552

Answers (1)

JustSid
JustSid

Reputation: 25318

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

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

Upvotes: 6

Related Questions