Fumbles
Fumbles

Reputation: 122

If let statement with CLPlacemark

I'm trying to make an if let statement with the following:

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

Currently it's telling me "Value of optional type 'CLPlacemark?' not unwrapped" and instructing me to put

(placemark: (placemarks?[0])!) {

However if I do that, it then tells me "Initializer for conditional binding must have optional type, not 'CLPlacemark'"

I honestly have no idea how to fix this and could use any help. Thanks in advance

Upvotes: 0

Views: 205

Answers (1)

Rashwan L
Rashwan L

Reputation: 38843

Try this

if let validPlacemark = placemarks?[0]{
     let placemark = validPlacemark as? CLPlacemark;
}

You need the ? because placemarks is not guaranteed to have a value

Upvotes: 1

Related Questions