1

由于我已更新到 Xcode 7 和 swift 2,因此出现以下错误:

模块'SQLite'中没有名为'Query'的类型使用未声明的类型'Database'

使用此代码:

let table:SQLite.Query

init(db:Database){

    table = db["BucketType"]
}

我正在使用 SQLite.swift 的 swift2 分支,但它看起来像我的项目,它找不到参考 SQLite.swift 模块。在我使用 SQLite.swift 的每个文件上也有 import SQLite。我已经尝试过手动集成和可可豆荚,但结果相同。

它正在使用 Xcode 6.4。

4

1 回答 1

3

我有这样的东西...

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 将是...

导入系统配置

类实用程序{

class func getDBPath() -> String {
    let path = NSSearchPathForDirectoriesInDomains(
        .DocumentDirectory, .UserDomainMask, true
    ).first

    return path!
}

}

希望这对您有所帮助。

于 2015-10-08T12:10:08.713 回答