Answer the question
In order to leave comments, you need to log in
How to fix error when connecting SQLite database in Swift?
When using SQLite.Swift to work with the application's SQLite database is built. But, after being immersed in the simulator, it crashes. I can't figure out what the problem is. Tell me who can?
Here is the code:
import Foundation
import SQLite
class Database {
static let shared = Database()
public let connection: Connection?
private init() {
let dbPath = Bundle.main.path(forResource: "sqliteExample", ofType: "db")! <i>// вот здесь ошибка!</i>
do {
connection = try Connection(dbPath, readonly: true)
} catch {
connection = nil
let nserror = error as NSError
print ("Cannot connect to Database. Error is: \(nserror), \(nserror.userInfo)")
}
}
}
Answer the question
In order to leave comments, you need to log in
Found a solution. The question is closed.
import Foundation
import SQLite
class Database {
static let shared = Database()
public let connection: Connection?
public let dbFileName = "Example.db"
private init() {
let dbPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first as String!
do {
connection = try Connection("\(dbPath!)/Example.db")
} catch {
connection = nil
let nserror = error as NSError
print ("Cannot connect to Database. Error is: \(nserror), \(nserror .userInfo)")
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question