apologies in advance. newbie learning swift , have working experience c , ruby. i'm venturing swift.
i'm trying create , access multi-dimensional array follows:
var arraytest: [[(int, int, int, string)]] = [] arraytest.append([(1, 2, 3, "test")]) arraytest.append([(4, 5, 6, "test1")]) this seems work fine in playground. trying access follows not work:
println(arraytest[0][0]) i looked @ several entries , apple swift docs. still unable figure out.
any insights appreciated. thank you.
looks you're trying make array of tuples have set of brackets, meaning you're making array of arrays of tuples. also, append tuple without putting in parenthesis. try:
var arraytest: [(int, int, int, string)] = [] arraytest.append(1, 2, 3, "test") arraytest.append(4, 5, 6, "test1") you access element little differently. square brackets return tuple in arraytest, , period returns element of tuple.
println(arraytest[0].0) this return 1 (the 0th element of 0th tuple).
Comments
Post a Comment