"downcast from CLplacemark? to Clplacemark only unwraps optional"(swift2) -
how fix error :
"downcast clplacemark? clplacemark unwraps optional"
so use code :
if let p = clplacemark(placemark: placemarks.first as? clplacemark){}
and change placemarks[0] array not work
and code :
clgeocoder().reversegeocodelocation(userlocation) { (placemarks, error) -> void in if error == nil { if let p = clplacemark(placemark: placemarks[0] as? clplacemark){ print(p) self.adsresslabel.text = "\(p.administrativearea)\(p.postalcode)\(p.country)" } }else { print (error) } }
at code :
if let p = clplacemark(placemark: placemarks[0] as? clplacemark)
i have error
"downcast clplacemark? clplacemark unwraps optional"
how fix error ?!
if don't need make copy of first placemark, need :
if let p = placemarks.first { print(p) self.adsresslabel.text = "\(p.administrativearea)\(p.postalcode)\(p.country)" }
on other hand, if need copy:
if let p0 = placemarks.first { let p = clplacemark(placemark:p0) print(p) self.adsresslabel.text = "\(p.administrativearea)\(p.postalcode)\(p.country)" }
Comments
Post a Comment