Skip to content

Instantly share code, notes, and snippets.

@desmondmc
Last active September 6, 2016 12:59
Show Gist options
  • Save desmondmc/6ace6e54adb7acc28f59e5e7fd3d4e6a to your computer and use it in GitHub Desktop.
Save desmondmc/6ace6e54adb7acc28f59e5e7fd3d4e6a to your computer and use it in GitHub Desktop.
Updateable Realm Object
extension Updateable where Self: RLMObject {
static func persistJSON(json: NSDictionary) {
let update = Self.partialUpdateDicWithJSON(json)
let realm = RealmPersister.realm
realm.beginWriteTransaction()
Self.createOrUpdateInRealm(realm, withValue: update)
try! realm.commitWriteTransaction()
}
}
extension MyRealmObject: Updateable {
static func partialUpdateDicWithJSON(json: NSDictionary) -> NSDictionary {
let updateDictionary = NSMutableDictionary()
// Add json dic to realm mapping here.
// updateDictionary["id"] = json["Id"]
return updateDictionary;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment