Skip to content

Instantly share code, notes, and snippets.

@herrkaefer
Created June 12, 2017 06:25
Show Gist options
  • Save herrkaefer/6e3ac0e561daaac8f3887166fee2bf11 to your computer and use it in GitHub Desktop.
Save herrkaefer/6e3ac0e561daaac8f3887166fee2bf11 to your computer and use it in GitHub Desktop.
Realm object operations: update value in DB, delete from DB, ...
import RealmSwift
extension Object {
// Update property value in Realm
func update(_ property: String, value: Any?) {
let realm = try! Realm()
try! realm.write {
self.setValue(value, forKey: property)
}
}
// Remove object from Realm
func remove() {
let realm = try! Realm()
try! realm.write {
realm.delete(self)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment