Cannot make Connection to SQLite database Swift 3 -
i'm using sqlite library , in usage says let db = try connection("path/to/db.sqlite3")
have sqlite database located in documents. when try make connection throw error call can throw errors cannot thrown out of property initializer
here's code :
import uikit import sqlite class searchviewcontroller: uiviewcontroller, uitextfielddelegate { let db = try connection("/users/macbookpro/documents/db.sqlite") //error let categoryvc = categoryviewcontroller() let usefullvc = usefullviewcontroller() let mapvc = mapviewcontroller() let eventvc = searchresultonlinevc() @iboutlet weak var searchtextfield: uitextfield! override func viewdidload() { super.viewdidload() self.title = "search" searchtextfield.delegate = self } override func didreceivememorywarning() { super.didreceivememorywarning() } }
i try put connection in viewdidload still doesn't work
what's wrong?
since connection
initializer can throw exception, need call in do/catch
block.
so should change declaration to:
var db : connection?
and initialize in viewdidload
:
do{ self.db = try connection("/users/macbookpro/documents/db.sqlite") } catch { print("unable create connection: \(error)") }
Comments
Post a Comment