سؤال

In restkit, at some scenario, I want to clear entity before refresh. I use followed code, it works.

[self clearcache]; //clear the entity
[manager getObjectsAtPath:self.path parameters:self.parameters success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    [self finishedLoadingWithItems:[mappingResult array]];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];

but now I want to clear cache only after the mapping is finish but before saving new items to entity. I try clearcache in followed function, but unfortunately this would also clear new items.

[self finishedLoadingWithItems:[mappingResult array]];
هل كانت مفيدة؟

المحلول 2

It depends on when you want to do the purge (after all requests?).

Generally, you want to use the fetch request block feature of RestKit (added to the object manager), where you specify a fetch request to execute which returns the objects which should be purged. RestKit will run this and delete the resulting objects during the mapping.

نصائح أخرى

finally, I write a method of addFetchRequestBlockOnce, it almost same with addFetchRequestBlock, but will be removed when it was executed.

[manager addFetchRequestBlockOnce:^NSFetchRequest *(NSURL *URL) {
}];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top