I have two objects:
deviceConfigInfo and deviceStatusInfo
Both contain an array of devices (so theres a third device object actually).
For each device returned in deviceConfigInfo there are these properties:
uuidnamesomethingElselookAnotherOne
and for deviceStatusInfo
uuidnamesomethingElsesomeStatusInfosomeMoreStuff
(If you hadn't guessed, I just made up some random properties)
So back to that third object I mentioned, device, I created it with all the properties combined. Now, my question is, say the deviceStatusInfo gets updated, how can I update the device object without losing the "old" data that isn't overwritten (in this case, the lookAnotherOne property).
Does it have to be a manual process of getting the device with the matching uuid and then updating each of the properties for deviceStatusInfo or is there a quicker way of doing this? Imagine there were loads of properties.
Hopefully this makes sense. If it helps, I am using Mantle to create the objects/models.
I noticed that Mantle has the following function which I was able to use:
mergeValueForKey:fromModel:So in my
devicemodel, I added two functions:mergeConfigInfoKeysFromModel:mergeStatusInfoKeysFromModel:These functions have access to an array that contains
NSStringvalues representing the properties/keys. There is one array for theconfigInfoand another forstatusInfoproperties/keys.I then loop through the keys and use
valueForKeyto check it has an actual value. If it does, I then call themergeValueForKey:fromModel:.Example Code:
All I have to do now, is call the appropriate merge function on the
deviceobject when I get an update, passing over the updateddeviceobject. Just as below: