问题
i use restkit to consume a web service ,, but when i get data i want to add some other parameters, i searched and i found that i should implement function called willsave but i don't know the way
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:brandId,@"brandId",categoryId,@"categoryId", nil];
[[RKObjectManager sharedManager] postObject:nil path:@"/mywebservice" parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[self getProductsList];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
回答1:
You don't need to use willSave
, it depends what you want to do...
You can use the success
block, iterate through the results provided in mappingResult
, make changes and then save the main thread MOC to the persistent store.
willSave
is a method on NSManagedObject
. So, you would implement it on the managed object subclasses. This will result in changes being saved as part of the mapping process, but it's only really useful for derived values / time-stamping.
来源:https://stackoverflow.com/questions/22388350/restkit-edit-inserting-in-coredata