ios - '[CLPlacemark]?' is not convertible to '[CLPlacemark]' -> swift2 -


this part of code found on stackoverflow.
working in swift 1.2 why code not working anymore in swift 2:

geocoder.reversegeocodelocation(location, completionhandler: { (placemarks, error) -> void in         let placearray = placemarks [clplacemark] // !!! error here !!!          // place details         var placemark: clplacemark!         placemark = placearray[0]          // address dictionary         print(placemark.addressdictionary)          // location name         if let locationname = placemark.addressdictionary["name"] as? nsstring {             print(locationname)         }          // street address         if let street = placemark.addressdictionary["thoroughfare"] as? nsstring {             print(street)         }          // city         if let city = placemark.addressdictionary["city"] as? nsstring {             print(city)         }          // zip code         if let zip = placemark.addressdictionary["zip"] as? nsstring {             print(zip)         }          // country         if let country = placemark.addressdictionary["country"] as? nsstring {             print(country)         }      }) 

error getlocationviewcontroller.swift:67:41: '[clplacemark]?' not convertible '[clplacemark]'

looks need unwrap placemarks array (implicitly or optional chaining) before assigning type of [clplacemarks]

for example, should use optional chaining so

if let validplacemark = placemarks?[0]{      let placemark = validplacemark as? clplacemark; } 

than place logic inside braces if finds valid placemark array, execute desired commands. if not, nothing or can handle please


Comments

Popular posts from this blog

python - How to create jsonb index using GIN on SQLAlchemy? -

PHP DOM loadHTML() method unusual warning -

c# - TransactionScope not rolling back although no complete() is called -