2015-09-26 19 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}