I'm trying to copy a file from my App's Bundle to the device and I'm getting a strange error: cannot convert the expression type '$T5' to type 'LogicValue'
I commented the line that is causing the problem in the code below.
Here's everything:
// 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
}
}
}
The App won't even compile right now. The issue seems to be specifically with the copyItemAtPath
call - which is supposed to return a Bool.
I'd appreciate any insights.
There's two issues here:
If you specify the error
variable as let
then it's not mutable and so you can't get an error value back.
You are supposed to send a pointer to the error
variable and not the variable itself. So in the line where you get the compiler error, it should be &error
and not error
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With