Skip to content

Instantly share code, notes, and snippets.

@jpsim
Created November 14, 2015 00:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpsim/a45f6194bc85008612ec to your computer and use it in GitHub Desktop.
Save jpsim/a45f6194bc85008612ec to your computer and use it in GitHub Desktop.
Realm.write() valid syntax
import RealmSwift
// Swift's syntax allows for a variety of ways to invoke closures.
// Here are some of them, specifically ways to making write transactions in Realm Swift.
// See https://realm.io/docs/swift/latest/#writes for Realm's docs on write transactions.
do {
let realm = try Realm()
// 1
realm.beginWrite()
try realm.commitWrite()
// 2
try realm.write {
}
// 3
try realm.write() {
}
// 4
try realm.write({
})
// 5: these closure arguments can be included in all other closure syntaxes as well
try realm.write { () -> () in
}
} catch {
// handle error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment