美文网首页
Swift: 'try!' expression unexpec

Swift: 'try!' expression unexpec

作者: SillyMichael | 来源:发表于2017-04-16 16:31 被阅读0次

今年把Swift2.3转成3的时候,由于早期sqlite包不是用swift3编译的,因此重新找了一个github上的sqlite库

在使用以下语句链接数据库时

import SQLite
let db = try! Connection("data.db")

错误提示:

'try!' expression unexpectedly raised an error: unable to open database

stackoverflow上找到解决方案

import SQLite
let path = NSSearchPathForDirectoriesInDomains(
            .documentDirectory, .userDomainMask, true
            ).first!
llet db = try! Connection("\(path)/data.db")

可以成功读取!

相关文章

网友评论

      本文标题:Swift: 'try!' expression unexpec

      本文链接:https://www.haomeiwen.com/subject/elvaattx.html