Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

casting

ios

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?

like image 424
john doe Avatar asked Nov 25 '15 03:11

john doe


1 Answers

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

placemark?.addressDictionary as? [String:AnyObject]
like image 74
Leo Avatar answered Nov 06 '22 10:11

Leo