I have written a class in Swift for Lat/Long and I want to place the Location on the view controller. I am using KVO as a part of MVC. I am just trialing at the moment but why doesn't
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let location = locations.last as! CLLocation
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, e) -> Void in
if let error = e {
println("Error: (e.localizedDescription)")
} else {
let placemark = placemarks.last as! CLPlacemark
LocationClass.addObserver(self, forKeyPath: "LocationString", options: .New, context: &self.myContext)
self.LocationManager.stopUpdatingLocation()
self.LocationString = "\(placemark.subLocality), \(placemark.locality)"
}
})
}
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject: AnyObject], context: UnsafeMutablePointer<Void>) {
println("Things have changed")
}
}
but why doesn't 'observeValueForKeyPath function get called ? Any ideas would be great. LocationString is a dynamic var at the top of the class. MyContext is just a var int = 0