2015-09-26 61 views
-1

我将Swift 1.2项目转换为Swift 2.0,迄今为止最大的错误是使用reverseGeocodeLocation()时,我的CLPlacemarks不再有效。 Xcode尝试正确解开它们,但卡住了。这是我在1.2中的代码:如何在Swift 2.0中正确解开这些CLPlacemarks?

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 

        } 
       } 

      } 
     }) 

我该如何正确实施它们?

回答

-1

,你应该简单地能够做到:

if let p = placemarks?[0}