how to make a swift dictionary that holds two items that are array of other items -
i'd create dictionary holds 2 arrays (one key called "locations" , other "items") this:
var tmpresults = dictionary("locations",array) tmpresults["items"]=array or (neither of seem work):
var tmpresults = ["locations",:<location>,"items":<item>] var tmpresults = ["locations":array(location),"items":array(item)] but i'm not sure how in swift. how specify types arrays hold?
i think easiest solution anyobject.
var tmpresults: [string: anyobject] = [:] tmpresults["locations"] = [location1, location2, location3] tmpresults["items"] = [item1, item2, item3] // assuming location1, location2, , location3 of same "location" type // , item1, item2, , item3 of same "item" type by using anyobject, dictionaries objects anything. in example, have dictionary holds , array of locations @ 1 key, , array of items @ key.
you lose of nice type-checking swift though.
edit
in fact, declare this, compiler @ least knows dictionary holds arrays:
var tmpresults: [string: [anyobject]] = [:] in either case, use array you'd this:
if let items = tmpresults["items"] as? [item] { // items here }
Comments
Post a Comment