我正在尝试加载带有 .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中
最佳答案
试试这个:
let dat = Bundle.main.path(forResource: "resource", ofType: "db3")!
let ddata = try! Connection(dat, readonly: true)
关于ios - 如何在 swift 中读取预加载的 sqlite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57628876/