按照stephencelis/SQLite.swift的文档,使用try后一直报错,是什么问题?
import SQLite
class CreateSQLiteDB{
let Sqlite3Path = NSSearchPathForDirectoriesInDomains(
.documentDirectory, .userDomainMask, true
).first! + "/db.sqlite3"
func createSQlite() {
let db = try Connection(Sqlite3Path)
let users = Table("users")
let id = Expression<Int64>("id")
let name = Expression<String?>("name")
let email = Expression<String>("email")
try db.run(users.create { t in
t.column(id, primaryKey: true)
t.column(name)
t.column(email, unique: true)
})
}
}
ringa_lee2017-04-18 09:49:13
先看一下拋出的異常吧,對症下藥。
swift 中,try-catch 的用法:
do {
try expression
} catch let error {
print(error)
}
Errors thrown from here are not handle 翻譯過來就是:这里抛出的异常并未处理
此外,還有 try? 和 try! 。建議稍微去了解一下。