So let's say I have a JSON object like such:
{
"userList" : [
{
"ID" : 1,
"firstName" : "John",
"lastName" : "Doe"
},
{
"ID" : 2,
"firstName" : "Jane",
"lastName" : "Doe"
}
]
}
I am able to map this object into my user
class which have the following attribute:
ID,
firstName,
lastName,
createdDate,
modifiedData
The Problem arise when I am need to update modified date
I want to be able to insert a data-time stamp whenever I do a mapping along with when I modified the data while in offline mode.
So my question is, how do I map JSON object to Core Data while also inserting some data that is not present in the JSON object. Is this even possible?
================
My Mapping Function, if it helps:
+ (RKObjectMapping *)mapping {
// Create a singleton instance of the mapping object.
__strong static RKEntityMapping *_mapping = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
RKManagedObjectStore *store = [[RKObjectManager sharedManager] managedObjectStore];
_mapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([self class]) inManagedObjectStore:store];
// Map attributes with the same name in the JSON and the model.
[_mapping addAttributeMappingsFromDictionary:@{@"ID": @"ID",
@"firstName" : @"firstName",
@"lastName" : @"lastName"}];
// Set primaryKeyAttribute
_mapping.identificationAttributes = @[@"ID"];
});
return _mapping;
}