Krishna Manda - 1 year ago 97
iOS Question

# Initializer For Conditional Binding Must Have Optional Type, not CLPlacemark

Noob programmer here.

I'm trying to become a good programmer with the help of the internet. So, I subscribed to Rob Percivals iOS class. I'm having trouble with this bit of my code. Must've been a recent update that's making it fail on my system although it is the same code as his.

CLGeocoder().reverseGeocodeLocation(userLocation) { (placemarks, error) in

if (error != nil) {

print(error)

} else {

if let p = CLPlacemark(placemark: placemarks![0] as! CLPlacemark) {

print(p)

}
}
}
}


Please try to put it in baby english if possible guys. Thanks!

placemarks is of type [CLPlacemark]?. Therefore you should try something like the following:
if let placemarks = placemarks {

Don't use !. Use if let instead.