這實際上是一本字典,所以我的傾向是將數據表示爲一個。
let array = [
["Reichertshofen", "ssh -p 10001 [email protected] -L 13389:192.168.23.14:3389 -f sleep 50"],
["Zentralbuero", "ssh -p 10001 [email protected] -L 13389:192.168.38.14:3389 -f sleep 50"]
]
斯威夫特4
let sequence = array.flatMap
{ entry -> (String, String)? in
guard entry.count == 2 else { return nil }
return (entry[0], entry[1])
}
let dictionary = Dictionary(uniqueKeysWithValues: sequence)
斯威夫特3
let dictionary = array.reduce([String:String]())
{ (dict, entry) in
guard entry.count == 2 else { return dict }
var dict = dict
dict[entry[0]] = entry[1]
return dict
}
形式存在,它只是:
if let result = dictionary["Reichertshofen"]
{
print(result)
}
任何理由次數據是不是在一個字典? – XmasRights
我從一個json文件中解脫出來,它就這樣結束了:-) – tpensel