Am just starting to use SQLite in Swift and am running into a declaration problem. I would like to wrap everything in one class that I can then call methods on.
My problem is I don't know how to declare db so that when I do call Connect, it can be filled in an always be available while the class exists. I could call connect at the init, but I don't want to call Connect until I need it. When I code it as below I get the following error:
Return from initializer without initializing all stored properties
class MySQL {
var db : Connection
var dbPath : String
init() {
dbPath = getDocumentsDirectory().absoluteString + "db.sqlite3"
}
func open(){
do{
db = try Connection(dbPath)}
catch{}
let users = Table("users")
print(users)
}
}