Øyvind Vik
Øyvind Vik

Reputation: 6257

Multi-Dimensional Arrays of Different Types in 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?

Upvotes: 5

Views: 4373

Answers (1)

erdekhayser
erdekhayser

Reputation: 6657

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)]] = []

Upvotes: 11

Related Questions