ios - Is there a way to save an array within an array using swift? -


is possible save array of names within array? example, lets have 2 car companies, toyota , honda. , lets want create array within car company array of cars make. example...

var arraywithinarray = ["toyota, "sienna", "camry"", "honda, "odyssey", "civic""] 

how using swift?

in such situation, can create dictionary of arrays this:

var listdata = [ "toyota": ["sienna", "camry"], "honda": ["odyssey", "civic"] ] 

to access particular model, ("sienna" here)

let model = listdata["toyota"]?.first ?? "car not found" 

model contain sienna

and if want iterate on models

for model in listdata["toyota"] ?? [] {     println(model) } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -