我想将国家/地区名称加载到数组中。这是我到目前为止的代码......
if let path = Bundle.main.path(forResource: "flagData", ofType: "plist") {
dict = NSMutableDictionary(contentsOfFile: path)
let currentGroup = (dict!["caribbean"] as AnyObject).allKeys as? [String]
}
但这不起作用 - 当我运行它时,currentGroup = nil
我也尝试过:
let currentGroup = dict?.allKeys(for: "caribbean")
但这给了我一个空数组。
任何想法都将不胜感激......谢谢!
答案 0 :(得分:1)
if let path = Bundle.main.path(forResource: "flagData", ofType: "plist"),
let configurations = NSDictionary(contentsOfFile: path) {
variables = configurations[currentConfiguration] as! NSDictionary
}
尝试上面的代码并进行相关更改我认为代码中的错误是在您失败的时候。