创建具有国名作为NSDictionary
国家作为keys
的状态values
,我想显示对应于一个国家的状态到另一个的tableView
首先,它是不是在迅速使用NSDictionary
一个好主意,你可以使用Dictionary
,在你的情况下,可以[String: [String]]
。
您可以创建这样一个迅速Dictionary
:
var countries = [
"country 1": "state one",
"country 2": "state 2"
]
要访问value
只是这样做:let state = countries["country 1"]
UPDATE
用状态的阵列是相同的,使之。
var countries = [
"country 1": [
"state 1",
"state2","state3",
"state4"
],
"country 2": [
"otherstate 1",
"otherstate",
"otherstate",
"otherstate"
]
]
值的存取阵列:
let states = countries["country 1"] as! [String]
for state in states {
print(state)
}