如何检查 plist
文件是否存在?
我正在尝试这样的事情:
if let dictFile = NSDictionary(contentsOfURL: "file.plist") {
}
但是我得到这个错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
是否要在使用前检查 plist
文件是否存在?
最佳答案
您应该使用 URLPath,按照您的方式,没有文件夹或引用。 我假设您在主包中使用 plist。
if let filePath = NSBundle.mainBundle().pathForResource("file", ofType: "plist"), let dataDictionary = NSDictionary(contentsOfFile: filePath){
.
.
.
}
关于Swift 检查 plist 文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39021541/