Last active
September 6, 2016 12:59
-
-
Save desmondmc/6ace6e54adb7acc28f59e5e7fd3d4e6a to your computer and use it in GitHub Desktop.
Updateable Realm Object
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
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