john doe
john doe

Reputation: 9660

Converting [NSObject, AnyObject] to [String, AnyObject] in Swift

I have the following line which used to work in iOS 8 in Swift.

 let placemark = placemarks![0] as? CLPlacemark

 let destinationPlacemark = MKPlacemark(

     coordinate: placemark!.location!.coordinate, 
     addressDictionary: placemark?.addressDictionary

 )

but now it gives me the following exception:

Cannot convert value of type '[NSObject : AnyObject]?' to expected argument type '[String : AnyObject]?'

How can I do that?

Upvotes: 9

Views: 4069

Answers (1)

Leo
Leo

Reputation: 24714

You need to cast the type to [String : AnyObject]

placemark?.addressDictionary as? [String:AnyObject]

Upvotes: 8

Related Questions