为什么在实例化之后才能获得EXC_BAD_ACCESS? [英] Why do I get EXC_BAD_ACCESS right after instantiation?

查看:750
本文介绍了为什么在实例化之后才能获得EXC_BAD_ACCESS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这个问题,仍然无法弄清楚什么。我把断点放在AA& BB,看到第一个AA发生,这意味着 destinationPlacemark 被实例化。稍后在BB线 po destinationPlacemark 并得到错误:

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 :


表达式生成错误:错误:执行中断,原因:
EXC_BAD_ACCESS(code = 1,address = 0x10)。该过程已经返回
到表达式求值之前的状态。

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!
    }
})
}

}


推荐答案

中的答案 destinationPlacemark = CLPlacemark()已实例化,但没有指定位置。那么位置被设置为这个零。我发贴了原来的问题。尝试chaning let location = self.destinationPlacemark.location to location = placemark.location

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

这篇关于为什么在实例化之后才能获得EXC_BAD_ACCESS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆