1

I was reading this question and still can't figure out something. I placed breakpoints at AA & BB and saw that first AA happens which means destinationPlacemark gets instantiated. later at line BB I po destinationPlacemark and get error :

expression produced error: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x10). The process has been returned to the state before expression evaluation.

I read some of the answers found here but they are talking about a released object. How can that object be released as quickly as such?!

import UIKit
import CoreLocation

class ViewController: UIViewController {


var destinationPlacemark = CLPlacemark() //AA

override func viewDidLoad() {
    super.viewDidLoad() //BB
    forwardGeocoding(address: "1 Infinite Loop, Cupertino, CA 95014")
}
func forwardGeocoding(address: String) {
CLGeocoder().geocodeAddressString(address, completionHandler: { (placemarks, error) in
    if error != nil {
        print(error ?? "Error in plscement conversion")
        return
    }
    if (placemarks?.count)! > 0 {
        let placemark = placemarks?[0]
        let location = self.destinationPlacemark.location
        let coordinate = location?.coordinate
        print("Latitude: \(coordinate!.latitude), Longitude: \(coordinate!.longitude)")

        self.destinationPlacemark = placemark!
    }
})
}

}
Community
  • 1
  • 1
mfaani
  • 33,269
  • 19
  • 164
  • 293
  • 1
    I _suspect_ that the reason is that you are not supposed to instantiate `CLPlacemark` just like that, via the constructor. You only can get it from the geocoder (like in the example). `CLPlacemark` is bridged from Obj-C where it inherits from `NSObject` that does provide you with zero-argument initializer, yes, however that one immediately returns null object. – 0x416e746f6e Jan 24 '17 at 23:16

1 Answers1

-1

as explained in the answer in destinationPlacemark = CLPlacemark() was instantiated but has no location specified. Then location is being set to this nil. I posted the original question. Try chaning let location = self.destinationPlacemark.location to location = placemark.location

Community
  • 1
  • 1
Syed Tariq
  • 2,878
  • 3
  • 27
  • 37