ios - Array of arrays in Swift -
i want make , array contains arrays, of double's, of int's.
this not work:
var arrayzero = [1,2,3] var arrayone = [4.0,5.0,6.0] var arrayofarrayzeroandone: [[anyobject]] = arrayzero.append(arrayone)
how can append arrays array can 5.0 if write arrayofarrayzeroandone[1][1] ?
i take advantage of swift's type safety. going route introduce bugs if you're not careful adding , retrieving array.
var numbers = array<array<nsnumber>>() // bit clearer imo var numbers = [[nsnumber]]() // way declare numbers.append(arrayzero) numbers.append(arrayone)
then when like
let 5 = numbers[1][1] // 5.0
you know of type nsnumber. further swift won't let put else array unless it's nsnumber
without appends solution
var numbers = array<array<nsnumber>>() [ [1,2,3,4], [1.0,2.0,3.0,4.0] ]
Comments
Post a Comment