Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OrderedDictionary can't convert value of type '[String : Double]' to specified type 'OrderedDictionary<Key, Value>'

I’m trying to use OrderedDictionary from Collections and I’m getting the following error when trying to convert a Dictionary to OrderedDictionary.

Cannot convert value of type '[String : Double]' to specified type 'OrderedDictionary<Key, Value>'

let values: [String: Double]

let sortedDict: OrderedDictionary<String, Double> = values

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The compiler won’t let you cast it directly. Instead, pass values to the initializer.

let sortedDict: OrderedDictionary<String, Double> = OrderedDictionary(uniqueKeysWithValues: values)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading