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
Post a Comment