I want to build a Dictionary app for iOS. I try to read data from sqlite database file with SQLite.swift here.
My code
func configureCell(){
//Todo: read sqlite file
//let path = Bundle.main.path(forResource: "taidict", ofType: "sqlite")!
do{
let path = Bundle.main.path(forResource: "taidict", ofType: "sqlite")!
let db = try Connection(path, readonly: true)
let users = Table("words")
let id = Expression<Int64>("id")
let word = Expression<String?>("word")
let shanword_uni = Expression<String>("shanword_uni")
for user in try db.prepare(users.select(id, word, shanword_uni)) {
print("id: \(user[id]), word: \(user[word]), meaning: \(user[shanword_uni])")
// id: 1, email: alice@mac.com
}
}catch{
print(error)
}
}
When I try to run, I have got an error like below.
2017-10-03 21:59:57.826502+0630 TaiDict[60682:516343] [MC] Lazy loading NSBundle MobileCoreServices.framework
2017-10-03 21:59:57.827558+0630 TaiDict[60682:516343] [MC] Loaded MobileCoreServices.framework
2017-10-03 21:59:57.841476+0630 TaiDict[60682:516343] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/saitanwgpha/Library/Developer/CoreSimulator/Devices/BA4F6AD0-6C4D-4F29-B0E0-34B9F63607A0/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
fatal error: 'try!' expression unexpectedly raised an error: Unexpected null value for column `"id"`: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.59/src/swift/stdlib/public/core/ErrorType.swift, line 181
2017-10-03 21:59:57.870943+0630 TaiDict[60682:516343] fatal error: 'try!' expression unexpectedly raised an error: Unexpected null value for column `"id"`: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.59/src/swift/stdlib/public/core/ErrorType.swift, line 181
Message from debugger: The LLDB RPC server has crashed. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.
How should I fix it? Please help me. Best, Sai Pha