Swift2 Swift 2 SQLite.Swift模块参考
由于我已更新到Xcode 7和swift 2,因此出现以下错误: 模块“SQLite”中没有名为“Query”的类型 使用未声明的类型“数据库” 使用此代码:Swift2 Swift 2 SQLite.Swift模块参考,swift2,sqlite.swift,Swift2,Sqlite.swift,由于我已更新到Xcode 7和swift 2,因此出现以下错误: 模块“SQLite”中没有名为“Query”的类型 使用未声明的类型“数据库” 使用此代码: let table:SQLite.Query init(db:Database){ table = db["BucketType"] } 我正在使用SQLite.swift的swift2分支,但它看起来像我的项目,它找不到引用SQLite.swift模块。 在我使用SQLite.swift的每个文件上都有导入SQLite。
let table:SQLite.Query
init(db:Database){
table = db["BucketType"]
}
我正在使用SQLite.swift的swift2分支,但它看起来像我的项目,它找不到引用SQLite.swift模块。
在我使用SQLite.swift的每个文件上都有导入SQLite。
我尝试过手动集成和可可豆,但效果相同
它使用的是Xcode 6.4。我有这样的东西
class DBHelper {
static let instance = DBHelper() // singleton
var db : Connection
init() {
do {
self.db = try Connection("\(Util.getDBPath())/db.sqlite3")
createTablesIfNotExists()
} catch {
Logger.error("Could not create a connection to database")
}
}
func createTablesIfNotExists() {
// Logs
let logs = Table(TLog.TABLE_NAME) // just the name of your table
do {
try db.run(logs.create(ifNotExists: true) { t in
t.column(TLog.ID, primaryKey: true) // Expression<Int>("id")
t.column(TLog.TS) // Expression<String>("ts")
t.column(TLog.TAG) // Expression<String>("tag")
t.column(TLog.TYPE) ...
t.column(TLog.CONTENT) ...
})
} catch {
Logger.error("Could not create table Logs")
}
}
希望这对您有所帮助。请查看此处的评论:也请快速查看swift-2分支机构的自述和文档,以获取其他更新。谢谢,我收到了它。现在,根据您的示例,我有了这个问题,让_appDb=try Connection(dbPath.relativePath!),但是如果从这里抛出错误,则无法处理。您需要将
try
包装到do
-catch
块中。阅读Swift 2中的错误处理了解更多信息。谢谢@stephencelis。请添加您的评论作为答案,在这种情况下,它将更加突出。
class func getDBPath() -> String {
let path = NSSearchPathForDirectoriesInDomains(
.DocumentDirectory, .UserDomainMask, true
).first
return path!
}