1

I can't find out how to write a multidemensional array using 'Swift' and parse it. The sample code below is what I need it to do. The sample is written in JavaScript because I can't find the correct syntax in Swift but that is what I need to convert it to:

var array = [{
   name:'Steve',
   dates:[
       '10-29-2016',
       '11-03-2016',
       ]
   },{
   name:'Bill',
   dates:[
       '08-13-2016',
       '01-20-2016',
        ]
    }
]

console.log(array[0].name)
// logs 'Steve'
console.log(array[0].dates[])
// logs '11-03-2016'

When I tried to write it in Swift I get a lot of syntax errors and from my research I am unable to find examples using this array syntax. Any ideas? Thanks in advance!

0

2 Answers 2

2

Here I'm creating a list of tuples, and the tuple consists of 1) name (of type String) and 2) dates (of type List of Strings).

var arr:[(name: String, dates: [String])] = [
    (name: "Steve", dates: ["10-29-2016", "11-03-2016"]),
    (name: "Bill", dates: ["10-29-2016", "11-03-2016"])
]
for tup in arr {
  print(tup.name)
  print(tup.dates)
}
Sign up to request clarification or add additional context in comments.

Comments

-1
import UIKit

var array = [

    ["name":"Steve",
    "dates":[
        "10-29-2016",
        "11-03-2016"
        ],
    ],

    [
        "name":"Bill",
        "dates":[
        "08-13-2016",
        "01-20-2016"
        ]
    ]
]

print(array[0])
print(array[0]["name"])

Comments

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.