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

How to initialize OrderedDictionary – Swift Collections

Reading from the github docs I can see how to use it, but when I try to initialize it (to empty):

var responses: OrderedDictionary = [:]

it says: Empty collection literal requires an explicit type

I tried this:

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

var responses: OrderedDictionary<String: <TransactionsDataItemsClassAModel>> = [:]

but doesn’t work, what’s the proper way to initialize this?

This is how I have initialized my non ordered diccionary:

var dataDiccionary: [String: [TransactionsDataItemsClassAModel]] = [:]

Thanks

>Solution :

The regular syntax for generic types is like Array<T> and Dictionary<K, V>

  • There’s short-hand syntax specific to Array and Dictionary: [T] and [K: V].

You’re confusing some things and combined the two into an an invalid middle-ground.

OrderedDictionary doesn’t have any special short-hands, so you would just treat it like any other generic type. The generic type parameters are specified with a comma separated list:

OrderedDictionary<String, [TransactionsDataItemsClassAModel]>
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