我正在为 Swift Sqlite 使用 GRDB 库。
我创建了一个连接类:
导入GRDB
var dbQueue: 数据库队列!
功能设置数据库(){
var config = Configuration()
config.readonly = true
config.foreignKeysEnabled = true
config.trace = { print($0)}
let databasePath = NSBundle.mainBundle().pathForResource("mydb", ofType: "sqlite")!
dbQueue = try! DatabaseQueue(path: databasePath, configuration: config)
}
我在方法中调用类:
func trovaCitta(luogoNascita: String)->CittaVO{
let citta:CittaVO = CittaVO()
dbQueue.inDatabase { db in
for row in Row.fetch(db, "SELECT * FROM comune where cod_catastale='" + luogoNascita + "'") {
citta.codIstat = row.value(named: "cod_istat")
citta.nome = row.value(named: "nome")
citta.codProvincia = row.value(named: "cod_provincia")
citta.codValidita = row.value(named: "cod_validita")
citta.codCap = row.value(named: "cod_cap")
citta.codCatastale = row.value(named: "cod_catastale")
// print(citta)
}
}
return citta
}
应用程序返回:致命错误:在展开可选值时意外发现 nil
0x1009f8764 <+36>: 移动 x4, x5 0x1009f8768 <+40>: bl 0x100a3add0 ; Swift 的函数签名特化。(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
有人可以给我建议吗?谢谢