Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Dimensional Arrays of Different Types in Swift

Tags:

swift

I can easily write a multi-dimensional array in Swift when all the dimensions are of the same type, for example:

var totalTime : [[Int]]

How would I get the first dimension to be String and the second dimension Int?

like image 710
Øyvind Vik Avatar asked Sep 21 '14 01:09

Øyvind Vik


1 Answers

I would recommend using an array of tuples instead. What you want could be accomplished using an array of type Any, but it is not a good idea.

Instead, your array should be [[(String, Int)]]. This would also be more compact than what you want to do.

var myArray: [[(String, Int)]] = []
like image 169
erdekhayser Avatar answered Oct 10 '22 08:10

erdekhayser