Krishna Manda Krishna Manda - 1 year ago 141
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) {


} else {

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



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

Answer Source

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

if let placemarks = placemarks {
    if let p0 = placemarks.first {
        print (p0)

Don't use !. Use if let instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download