Created
June 12, 2017 06:25
-
-
Save herrkaefer/6e3ac0e561daaac8f3887166fee2bf11 to your computer and use it in GitHub Desktop.
Realm object operations: update value in DB, delete from DB, ...
This file contains 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 | |
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