jeudi 12 février 2015

Using FMDB to Rollback Transactions in Swift

So I am trying to use FMDB in Swift. I have everything hooked up fine as far as bridging headers and such, but I can't for the life of me figure out how to use transactions in the FMDatabaseQueue class. Specifically I do not understand the syntax to rollback a transaction. I have tried the code below but it yields a compile time error of



'UnsafeMutablePointer<ObjCBool>' does not have a member named 'initialize'


I am sure this has to do with the fact that a pointer is being passed into the closure for rollback, but as far as I am aware you cannot reassign variables passed into closures in swift, so I'm not sure how I am suppose to set the pointer to indicate a rollback is needed.



if let queue = FMDatabaseQueue(path: DB_PATH) {
queue.inTransaction() {
db, rollback in

// This could be any statement, drop table is just an example
success = db.executeUpdate("DROP TABLE test", withArgumentsInArray:nil)

if !success {
// Need to rollback here
rollback.initalize(true)
return
}
}
}


What do I need to do to indicate a rollback?


Aucun commentaire:

Enregistrer un commentaire