Permalink
Browse files

Update README for Swift 3

Notably, in `inTransaction`, in Swift 3:

 - the parameters are optionals (because FMDB has not yet been audited for nullability) and
 - `memory` has been replaced with `pointee`.
  • Loading branch information...
1 parent 94f9527 commit c28d787daf3f1bc131ac01c2147727f1c0406fb9 @robertmryan robertmryan committed 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 c28d787

Please sign in to comment.