Louis Lee Louis Lee - 1 year ago 96
iOS Question

IOS Swift 2 - How to construct multidimensional array

How can I achieve the following output:

rsPool[0][p1] = "123"
rsPool[0][p2] = "234"
rsPool[1][p1] = "abc"
rsPool[1][p2] = "bcd"

I deserialized from JSON output, which has the following data

first dimention > type (1 to 7)
second dimention > p1...P10
value > xxxx

I have tried to create:

var rspool : [Int: String] : []

but I don't know how to add/append to the array.

Answer Source

Your data seems to be this:

var rsPool = [
        "p1": "123",
        "p2": "234"
        "p1": "abc",
        "p2": "bcd"

which is of type [Dictionary<String, String>]

So the declaration should be:

var rsPool: [[String:String]]

Here's Playground reference: play

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download