RestKit not deleting orphaned objects from local store

让人想犯罪 __ 提交于 2019-12-03 12:05:46

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!