views:

898

answers:

1

Hi Team,

In iPhone SDK, can we only observe Objects, and not struts like CLLocationCoordinate2D?

Example: I've got some very simple code where I'd like to observe a property of type CLLocationCoordinate2D, I've made sure to synthesize it in ABC.m.

@interface ABC { CLLocationCoordinate2D currentLocation; } @property (nonatomic, readwrite) CLLocationCoordinate2D currentLocation;

Now in another class I do: [ABC addObserver:self forKeyPath:@"currentLocation" options:NSKeyValueObservingOptionNew context:NULL];

For some reason, the observeValueForKeyPath method never reports that keypath "currentLocation" changed.

Thanks,

Sjs

A: 

Is this the literal call that you make?

[ABC addObserver:self forKeyPath:@"currentLocation" options:NSKeyValueObservingOptionNew context:NULL];

If so then I think the issue is that you are observing the class ABC and not an instance of the class ABC. Assuming that you have an instance of class ABC try observing that.

ABC* myObject = [ [ [ ABC alloc ] init ] autorelease ];
[ myObject addObserver: self forKeyPath: @"currentLocation" options: NSKeyValueObservingOptionNew context: NULL ];
Jon Steinmetz