Created
November 14, 2015 00:16
-
-
Save jpsim/a45f6194bc85008612ec to your computer and use it in GitHub Desktop.
Realm.write() valid syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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