You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In instances where a PATCH endpoint requires only the changes be sent, it would be helpful to have a convenience method to get a dictionary of only those values which have changed.
Here's how I had this at least quasi-working in Swift, assuming the MOC hasn't been saved:
func dictionaryOfChangedValues() -> [String : AnyObject] {
let changedValuesFromCoreData = self.changedValues()
let classMapper = VOKCoreDataManager.sharedInstance().mapperForClass(User.self)
let changedCoreDataKeys = changedValuesFromCoreData.keys
let changedForeignKeys = changedCoreDataKeys.flatMap {
key in
return classMapper[key] as? String //
}
var returnDictionary = [String : AnyObject]()
for (key, value) in self.vok_dictionaryRepresentation() {
if changedForeignKeys.indexOf(key) != nil {
returnDictionary[key] = value
}
}
return returnDictionary
}
The text was updated successfully, but these errors were encountered:
Note that this is using the User.self method to grab the mapper because if I used self.dynamicType, I was getting not the User class but its parent class, which returned the wrong maps. I still have no idea why.
In instances where a
PATCH
endpoint requires only the changes be sent, it would be helpful to have a convenience method to get a dictionary of only those values which have changed.Here's how I had this at least quasi-working in Swift, assuming the MOC hasn't been saved:
The text was updated successfully, but these errors were encountered: