【发布时间】:2014-09-10 03:55:27
【问题描述】:
我正在尝试将文件从我的应用程序包复制到设备,但我收到了一个奇怪的错误:cannot convert the expression type '$T5' to type 'LogicValue'
我在下面的代码中注释了导致问题的行。
一切都在这里:
// This function returns the path to the Documents folder:
func pathToDocsFolder() -> String {
let pathToDocumentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
return pathToDocumentsFolder.stringByAppendingPathComponent("/moviesDataBase.sqlite")
}
override func viewDidLoad() {
super.viewDidLoad()
let theFileManager = NSFileManager.defaultManager()
if theFileManager.fileExistsAtPath(pathToDocsFolder()) {
println("File Found!")
// And then open the DB File
}
else {
// Copy the file from the Bundle and write it to the Device:
let pathToBundledDB = NSBundle.mainBundle().pathForResource("moviesDB", ofType: "sqlite")
let pathToDevice = pathToDocsFolder()
let error:NSError?
// Here is where I get the error:
if (theFileManager.copyItemAtPath(pathToBundledDB, toPath:pathToDevice, error:error)) {
// success
}
else {
// failure
}
}
}
应用程序现在甚至无法编译。这个问题似乎与copyItemAtPath 调用有关——它应该返回一个布尔值。
如果有任何见解,我将不胜感激。
【问题讨论】:
标签: swift bundle nsfilemanager