How to manually set the value of a managed object property in RestKit when it is controlled by the object manager?
I created an RKObjectManager with persistent storage to save master data.
I added the RKEntityMapping and RKResponseDescriptor object manager.
Now I can call the object manager as follows:
[[RKObjectManager sharedManager] getObjectsAtPath:@"/path_to_ressource" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { // success } failure:^(RKObjectRequestOperation *operation, NSError *error) { // report error }];
And the data displays well in a UITableView (for this I use NSFetchedResultsController). Everything looks good, my data is saved.
Now I want to add a property to the entity, which depends on the key path of the response descriptor. How do I do this and where?
My first attempt:
I added a property to the main data object, and then I tried this in the success block of the code above:
for (Entity *s in mappingResult.dictionary[@"CurrentEntities"]) { s.isCurrent = [NSNumber numberWithBool:YES]; } for (Entity *s in mappingResult.dictionary[@"OldEntities"]) { s.isCurrent = [NSNumber numberWithBool:NO]; }
assuming json looks like this:
{ CurrentEntities: [{ id: 10, title: "bhubhbhu"}, { id: 11, title: "ezeze"}, ...], OldEntities: [{ id: 0, title: "rf-reref"}, { id: 1, title: "vcvcvcvcv"}, ...] }
After setting a new local YES or NO property, I can really see the result in the table view, but it looks like these changes are not saved.
So any ideas?
EDIT:
Well, preserving the context seems to make the changes right:
NSError *error = nil; [[RKManagedObjectStore defaultStore].mainQueueManagedObjectContext saveToPersistentStore:&error];
EDIT:
Actually, it looks like I have to keep the context after every change to the object, otherwise I get Core Data errors.