从plist获取对象

时间:2019-05-29 02:58:52

标签: swift

您好,下面是我的plist文件的结构

s

请向我建议一种获取所有对象的方法,例如rnameArray,foodsArray等。我尝试使用以下扩展名,但对我不起作用

extension Dictionary {
init(plistNamed fileName: String, bundle: NSBundle = NSBundle.mainBundle()) {
guard
let pList = bundle.pathForResource(fileName, ofType: "plist"),
let dict = NSDictionary(contentsOfFile: pList)
else { self = [:]; return }
var result = [Key: Value]()
        dict.forEach { key, value in
if let key = key as? Key, let value = value as? Value {
                result[key] = value
            }
        }
self = result
    }
}

0 个答案:

没有答案