因为我已经更新到了Xcode 7和swift 2,所以我得到了这个错误:
模块'SQLite‘中没有名为'Query’的类型使用未声明的类型'Database‘
使用以下代码:
let table:SQLite.Query
init(db:Database){
table = db["BucketType"]
}我使用的是SQLite.swift的swift2分支,但它看起来像我的项目,它找不到引用的SQLite.swift模块。我还可以在我使用SQLite.swift的每个文件上导入SQLite。我尝试了手动集成和可可豆荚,但效果相同。
它使用的是Xcode6.4。
发布于 2015-10-08 20:10:09
我有这样的东西..。
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")
}}
然后..。Util.getDBPath将会是...
导入SystemConfiguration
类实用程序{
class func getDBPath() -> String {
let path = NSSearchPathForDirectoriesInDomains(
.DocumentDirectory, .UserDomainMask, true
).first
return path!
}}
希望这能对你有所帮助。
https://stackoverflow.com/questions/32651606
复制相似问题