MantisShrimp
MantisShrimp

Reputation: 171

How can I properly unwrap these CLPlacemarks in Swift 2.0?

I am converting my Swift 1.2 project into Swift 2.0, and the biggest error so far is that when using reverseGeocodeLocation(), my CLPlacemarks no longer work. Xcode attempts to unwrap them properly but gets stuck. Here is my code that worked in 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

                    }
                }

            }
        })

How can I properly implement them?

Upvotes: -1

Views: 434

Answers (1)

Kingsley Obi
Kingsley Obi

Reputation: 1

you should simply be able to do:

if let p = placemarks?[0}

Upvotes: -1

Related Questions