RestKit not deleting orphaned objects from local store

前端 未结 1 467
南旧
南旧 2021-02-14 13:58

Hi i have updated RestKit from 0.10.2 to 0.20.3. After updating now when objects are missing from web service, RestKit not deleting them from local storage. I know it is support

相关标签:
1条回答
  • 2021-02-14 14:19

    Finally solved the problem by debugging RestKit step by step and found this code in RKManagedObjectRequestOperation.m

    if (! [[self.HTTPRequestOperation.request.HTTPMethod uppercaseString] isEqualToString:@"GET"]) {
            RKLogDebug(@"Skipping deletion of orphaned objects: only performed for GET requests.");
            return YES;
        }
    

    Oh! RestKit doesn't delete orphan objects when the request method is POST. I changed the web services the accept GET request too and it worked perfectly. Secondly i was using predicate

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_id == %@", [DBUser currentUser].user_id];
    

    It was wrong, to delete all objects except current user, i had to append NOT operator, like this

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_id != %@", [DBUser currentUser].user_id];
    

    So predicate doesn't mean what you want, but it is what you don't want.

    0 讨论(0)
提交回复
热议问题