KVO message was received but no problems were handled - SWIFT

All,

I have a working KVO request. I have a location class and a view controller. when the button is clicked on the view controller it triggers the location class to get the GEOLOCATION. and then it runs KVO and the view controller picks up the changes and then navigates to the label in the view controller.

I am getting this error:

 An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.

      

Here is my code: In the locationManager class:

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
                self.LocationString = "\(placemark.subLocality), \(placemark.locality)"
                self.addObserver(self, forKeyPath: "LocationString", options: .New, context: nil)
                self.LocationManager.stopUpdatingLocation()
            }
        })

      

In my view controller:

  override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject: AnyObject], context: UnsafeMutablePointer<Void>) {


    }

      

+3


source to share


1 answer


Like apple doc "Using Swift with Cocoa and Objective-c", you need to remove the observer in deinit



deinit{
self.removeObserver(self, forKeyPath: , context:);
}

      

-1


source







All Articles