Permalink
Browse files

Merge pull request #563 from robertmryan/master

Update README for Swift 3
2 parents 94f9527 + c28d787 commit 08d74004ba1934b9121296749228b456e70506b6 @ccgus committed on GitHub Jan 4, 2017
Showing with 11 additions and 9 deletions.
  1. +11 −9 README.markdown
View
@@ -259,33 +259,35 @@ An easy way to wrap things up in a transaction can be done like this:
*rollback = YES;
return;
}
- // etc…
- [db executeUpdate:@"INSERT INTO myTable VALUES (?)", @4];
+
+ // etc ...
}];
```
-The Swift equivalent would be:
+The Swift 3 equivalent would be:
```swift
queue.inTransaction { db, rollback in
do {
- try db.executeUpdate("INSERT INTO myTable VALUES (?)", values: [1])
- try db.executeUpdate("INSERT INTO myTable VALUES (?)", values: [2])
- try db.executeUpdate("INSERT INTO myTable VALUES (?)", values: [3])
+ try db?.executeUpdate("INSERT INTO myTable VALUES (?)", values: [1])
+ try db?.executeUpdate("INSERT INTO myTable VALUES (?)", values: [2])
+ try db?.executeUpdate("INSERT INTO myTable VALUES (?)", values: [3])
if whoopsSomethingWrongHappened {
- rollback.memory = true
+ rollback?.pointee = true
return
}
- try db.executeUpdate("INSERT INTO myTable VALUES (?)", values: [4])
+ // etc ...
} catch {
- rollback.memory = true
+ rollback?.pointee = true
print(error)
}
}
```
+(Note, in Swift 3, use `pointee`. But in Swift 2.3, use `memory` rather than `pointee`.)
+
`FMDatabaseQueue` will run the blocks on a serialized queue (hence the name of the class). So if you call `FMDatabaseQueue`'s methods from multiple threads at the same time, they will be executed in the order they are received. This way queries and updates won't step on each other's toes, and every one is happy.
**Note:** The calls to `FMDatabaseQueue`'s methods are blocking. So even though you are passing along blocks, they will **not** be run on another thread.

0 comments on commit 08d7400

Please sign in to comment.