The main reason the KVO notification is not firing from the Location Model code is probably this line in the locationManager:didUpdateLocations
delegate method:
_currentLocation = locationFix;
The code is assigning a value directly to the backing variable of the property you want to observe.
Automatic KVO notifications only fire if you use the synthesized property setter:
self.currentLocation = locationFix; // <-- assign using self.xxx
A bit unrelated but in the observeValueForKeyPath
method:
- I'm not sure why you're checking
if ([keyPath isEqual:@"locationUpdated"])
. Are you sure that's thekeyPath
you want to look for? In this code:
CLLocation *locationVariable = [[CLLocation alloc]init]; locationVariable = self.location.currentLocation;
the alloc+init is unnecessary since the variable is then immediately assigned a new value. Just do:
CLLocation *locationVariable = self.location.currentLocation;