如何快速读取预加载的sqlite数据库

时间:2019-08-23 15:06:57

标签: ios swift xcode sqlite.swift

我正在尝试加载扩展名为.db3的预加载sqlite数据库,但出现错误“意外找到nil”

我将文件嵌入了targetapp >> BuildPhases >>复制捆绑软件资源。

let dat = Bundle.main.path(forResource: "resource", ofType: "db3")
let ddata = try! Connection(dat!, readonly: true)

do{
    for row in try ddata.prepare("SELECT id FROM Categories") {
        print("id\(row[0])")
}
}catch {
    print(error.localizedDescription)
}

我想将数据加载到我的collectionView

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

let dat = Bundle.main.path(forResource: "resource", ofType: "db3")!
let ddata = try! Connection(dat, readonly: true)