Skip to content

Instantly share code, notes, and snippets.

@insidegui
Last active July 10, 2017 18:21
Show Gist options
  • Save insidegui/dc41d2e523148bb2bfb43f8ef793fe83 to your computer and use it in GitHub Desktop.
Save insidegui/dc41d2e523148bb2bfb43f8ef793fe83 to your computer and use it in GitHub Desktop.
public class ModelObject: Object {
@objc public override func setValue(_ value: Any?, forKey key: String) {
// make sure we begin a write transaction if this is a managed object
self.realm?.beginWrite()
// actually do the update
super.setValue(value, forKey: key)
// commit the write transaction if managed
// this will crash if the write fails, in the real world you'd want to use do { } catch { }
try! self.realm?.commitWrite()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment