【问题标题】:How can I properly unwrap these CLPlacemarks in Swift 2.0?如何在 Swift 2.0 中正确解开这些 CLPlacemarks?
【发布时间】:2015-09-26 03:20:36
【问题描述】:

我正在将我的 Swift 1.2 项目转换为 Swift 2.0,到目前为止最大的错误是使用 reverseGeocodeLocation() 时,我的 CLPlacemarks 不再工作。 Xcode 尝试正确解包但卡住了。这是我在 1.2 中工作的代码:

CLGeocoder().reverseGeocodeLocation(savedLocation, completionHandler: { (placemarks, error) -> Void in

            if error != nil {

                print(error)

            } else {

                if let p = CLPlacemark(placemark: (placemarks?[0] as? CLPlacemark))
//The above line is where it's having trouble

                {

                    if p.subThoroughfare != nil {

                        self.address = "\(p.subThoroughfare) \(p.thoroughfare) \(p.locality) \(p.postalCode)"
                        self.annotation.subtitle = self.address

                    }
                }

            }
        })

如何正确实施它们?

【问题讨论】:

    标签: ios swift2 xcode7 cllocation clplacemark


    【解决方案1】:

    你应该能够做到:

    if let p = placemarks?[0}
    

    【讨论】: