2

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

Any help ?

1 Answer 1

1

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>.

Sign up to request clarification or add additional context in comments.

3 Comments

(Dictionary<String:String> was the syntax used in early Swift releases.)
Hmm... I hope the OP is up-to-date with Swift :)
What do you mean by "it didn't work": did you get a crash, or did the if code was not executed? Could you also give some sample of the Objective-C array you are trying to convert?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.