【发布时间】:2016-01-31 19:24:13
【问题描述】:
我真的对这个感到困惑。网上有很多问题在问“如何在 Swift 中从我的 plist 文件中获取信息?”并且到处都发布了相同的答案:
let path = NSBundle.mainBundle().pathForResource("Config", ofType: "plist")
然而,这条生产线总是为我产生nil。我已将 Config 替换为默认 plist 文件中的其他组件,但也得到了 nil。
我正在尝试访问我的自定义 ProductIdentifiers 数组,如下所示:
let url = NSBundle.mainBundle().URLForResource("ProductIdentifiers", withExtension: "plist")!
var productArray = NSArray(contentsOfURL: url) as! [[String:AnyObject!]]
我在 productArray 上收到一个声明 fatal error: unexpectedly found nil while unwrapping an Optional value 的崩溃。我还尝试使用其他默认 plist 值代替 ProductIdentifiers。
有谁知道为什么这对我不起作用,即使周围有很多人成功使用它?
【问题讨论】: