I use a sqlite database for a project. I can do queries like SELECT but impossible to do INSERTs! On the simulator the INSERT works properly. As soon as I compile on my iPod
Swift 3 using GRDB
var dbQueue: DatabaseQueue!
func setUpDatabasePath()
{
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! as NSString
let databasePath = documentsPath.appendingPathComponent("your_database.sqlite")
print("DATABASE PATH !!!!")
print(databasePath)
let fileManager:FileManager = FileManager.default
var success = fileManager.fileExists(atPath: databasePath)
if (success)
{
dbQueue = try! DatabaseQueue(path: databasePath)
print("writing to documents directory")
print(databasePath)
//break
return
}
if (!success)
{
let bundlePath = Bundle.main.path(forResource: "your_database", ofType: "sqlite")
success = fileManager.fileExists(atPath: bundlePath!)
print("writing from app bundle")
if (success)
{
try! fileManager.copyItem(atPath: bundlePath!, toPath: databasePath)
dbQueue = try! DatabaseQueue(path: databasePath)
}
else
{
print("Could not find database")
}
return
}
}