samedi 24 janvier 2015

Swift: fileExistsAtPath returning TRUE

I'm experimenting a weird issue detecting if a file exists or not.


I'm working with SQLite, so I have a DB file in my App, which is Member of my Project in Target Membership, it's only the DB structure.


In my AppDelegate I'm checking if the file exists:



let fm = NSFileManager.defaultManager()

var docDir = ""

docDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String

let dbName:String = String.fromCString("db22.sqlite3")!

let path = docDir.stringByAppendingPathComponent(dbName)


In that point the file is created (not the idea), when I print the path, the file exist with size 0.



println("Database path: \(path)")



-rw-r--r-- 1 LLL staff 0 Jan 24 22:49 /Users/LLL/Library/Developer/CoreSimulator/Devices/F18F613D-B032-4B0A-87FC-3E484FC0C024/data/Containers/Data/Application/74FE784B-F131-4C60-9846-21D115E08594/Documents/db22.sqlite3



Just before run the app:



$ find /Users/LLL/Library/Developer/ -name db22.sqlite3



Nothing there.


So my next if in order to check if the file exists or not, is always returning TRUE:



if !(fm.fileExistsAtPath(path)) {
...
...
fm.copyItemAtPath(from, toPath: path, error: &error)
...
...


I tried with Reset Content and Settings in the Simulator, and also closing the project and deleting the all the files and directories in Library/Developer//Xcode/DerivedData/


But the results are the same (Product -> Clean also in XCode).


I was using this file before, working just fine, copying it to my DocumentDirectory in order to modify my DB, I deleted because I changed something in the tables, and suddenly was not working anymore.


If I tried changing the name dbName variable to something that I've never used before, then the file is not created, and the fileExistsAtPath is returning FALSE, as it should be doing also with the previous one.


I also deleted the db22.sqlite3 from my XCode Project, I cleaned and Cleared all the settings, deleting all the files in DerivedData...but the same result.


Any ideas?


Thanks in advance guys!


Aucun commentaire:

Enregistrer un commentaire