I have an iOS app that uses sqlite3 and I\'m facing issues with multi-threading crashing the app with the illegal multi-threaded access to database connec
In case of any one faced this problem in Swift. Solution will be:
let dbName = "first.db"
static let shared = DatabaseManger()
var db: OpaquePointer?
private init(){
print("singletone initialized")
sqlite3_shutdown();
let dbPath = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
.appendingPathComponent(dbName)
if sqlite3_open_v2(dbPath.path, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, nil) == SQLITE_OK {
print("Successfully opened database connection at \(dbPath.path)")
}
else {
print("unable to open database connection")
}
}
This code tested in swift version 4.0 and 4.2