我有一个具有这种结构的 plist。
Root
item0 Dictionary
village string
bars array
item0 dictionary
name string
item1 dictionary
name string
item2 dictionary
item1 Dictionary
village string
bars array
item0 dictionary
name string
item1 dictionary
name string
item2 dictionary
在我的代码中,我想访问特定村庄的 bars 数组,然后遍历 bar 数组中的所有字典并输出每个字典中的字符串值。
到目前为止,我必须访问 plist 并获取村庄。
var villages = [AnyObject]()
let filePath = Bundle.main.path(forResource: "Bars", ofType: "plist")
if let path = filePath {
villages = NSArray(contentsOfFile: path) as! [AnyObject]
}
从这里我将如何访问我的 villages 数组以获取该 villages 数组中特定索引处的条(数组)?
然后我如何从那里访问 bars dictionary[index].string 值?
最佳答案
let bars = villages[index]["bars"] as! NSArray //get specific index bars in villiages
let name = (bars[index] as! NSDictionary)["name"] as! String //get specific index name in bars
关于ios - 访问 plist 数组 Swift XCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42847472/