Please refer to the answer of FMDatabaseQueue How To Return A Value. It said the function just return the value at the end of the function. But my code in swift doesn't work this way. Here is my code:
class func isSomethingRight()-> Bool {
var ret : Bool = false
self.queue.inDatabase({ database in
let sql = NSString(format: "SELECT * FROM Table WHERE tableId = '1001'")
if let resultSet = database.executeQuery(sql, withArgumentsInArray:nil) {
if resultSet.next() {
ret = true
}
}
})
return ret
}
In my code, the return ret return first, then the ret = true inside block (closure) called later. What could be wrong in my code? (Actually the exactly same code works in my another project in Swift).