我在一些新的Swift代碼中使用FCModel來保存我的模型數據。在我的模式管理/遷移代碼中,當我對Int進行邏輯比較時,出現編譯時錯誤。我不知道這裏是否有語法或類型錯誤,或者是否發現了編譯器錯誤。爲什麼Swift編譯器會拋出:「找不到接受提供參數的'<'的重載」
這是一個有效的邏輯操作?我錯過了一個錯誤嗎?
Error: AppDelegate.swift:53:30: Could not find an overload for '<' that accepts the supplied arguments
相關代碼:
var schemaVersion: Int = (settings["schemaVersion"] as String).toInt()!
FCModel.openDatabaseAtPath(databasePath, withSchemaBuilder: { database, schemaVersion in
database.crashOnErrors = true
database.traceExecution = true
database.beginTransaction()
// 'failedAt' closure removed for brevity
if schemaVersion < 1 { // ERROR HAPPENS HERE
if !database.executeUpdate("SQL STATEMENT HERE", withArgumentsInArray: nil)
{ failedAt(1) }
schemaVersion = 1
}
更新 openDatabaseAtPath()
被定義爲:
func openDatabaseAtPath(path: String!, withSchemaBuilder schemaBuilder: ((FMDatabase!, CMutablePointer<CInt>) -> Void)!)
更新#2 隨着Sulthan的幫助下,我認爲我已經收窄問題在哪裏,但我沒有ide爲什麼。再次,我認爲這可能是Swift中的一個錯誤。
更新代碼:
var schemaVersion: Int = 0
let database: FMDatabase = FMDatabase(path: databasePath)
FCModel.openDatabaseAtPath(databasePath, withSchemaBuilder: { (database, schemaVersion: CMutablePointer<CInt>) in
var x:Int = Int(schemaVersion.withUnsafePointer({ (unsafeSchemaVersion: UnsafePointer<CInt>) -> CInt in
return unsafeSchemaVersion.memory
}))
...
})
當我調試,並使用Xcode中一些有趣的事情發生在REPL。當執行在withSchemaBuilder
模塊中時database
不爲零,並與上面創建的對象匹配。 schemaVersion
是無法識別的標識:
error: use of unresolved identifier 'schemaVersion'
schemaVersion
和:
$R0: FMDatabase! = {
Some = {
NSObject = {
isa = FMDatabase
}
_db =
_databasePath = @"/Users/brian/Library/Developer/CoreSimulator/Devices/25115FDE-0DA8-4F2B-B4E5-5A0600720772/data/Containers/Data/Application/579A64D7-6C6B-4690-B503-2CA5B4229D55/Documents/userData.sqlite"
_logsErrors = YES
_crashOnErrors = NO
_traceExecution = NO
_checkedOut = NO
_shouldCacheStatements = NO
_isExecutingStatement = NO
_inTransaction = NO
_maxBusyRetryTimeInterval = 2
_startBusyRetryTime = 0
_cachedStatements = nil
_openResultSets = 0 objects
_openFunctions = nil
_dateFormat = nil
}
}
有什麼想法?
Xcode檢查器顯示'schemaVersion'定義爲'CMutablePointer',它沒有將'memory'定義爲屬性。 –
blundin
@blundin我在哪裏使用'schemaVersion.memory'? – Sulthan
當我清理名稱衝突並專注於我的邏輯時,這對我有用。謝謝! – blundin