Abdelrahman
Abdelrahman

Reputation: 1027

Convert from Objective-C NSArray to swift [[String:String]]?

I want to convert from NSArray to swift array [Dictionary<String:String>]

Any help ?

Upvotes: 2

Views: 1074

Answers (1)

Cristik
Cristik

Reputation: 32786

Simple as that:

let someArray = myArray as? [[String:String]]

Optional casting is recommended if you want to make sure you don't get any crashes when converting. You can then use it in if-let constructions like this:

if let dictArray = myArray as? [[String:String]] {
    // do something with the array of dictionaries
}

BTW, your initial definition was not correct, there's no such thing as Dictionary<String:String>, the correct definition is Dictionary<String, String>.

Upvotes: 1

Related Questions