I have fetched a lot of forums but still found no answer on the issue I have.
I load data from some URL. Items I receive contain 'deleted' property that I rely on when displaying objects in tableView.
- (void)loadData
{
[self showLoadingIndicatorView];
[[RKObjectManager sharedManager] getObjectsAtPath:@"/api/news/index.json"
parameters:@{@"auth_token" : [BMWConstants authToken]}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Load complete: Table should refresh...");
[super hideLoadingIndicatorView];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Load failed with error: %@", error);
[BMWSuperViewController showGhostAlert:error];
[super hideLoadingIndicatorView];
}];
}
I create a fetch result controller with a predicate
(NSFetchedResultsController*)fetchedResultsController
{
if (_fetchedResultsController != nil)
{
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"News"];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"deleted = NO OR deleted = NIL"]];
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:NO];
fetchRequest.sortDescriptors = @[descriptor];
[fetchRequest setFetchBatchSize:10];
NSError *error = nil;
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[RKManagedObjectStore defaultStore].mainQueueManagedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self.fetchedResultsController setDelegate:self];
BOOL fetchSuccessful = [self.fetchedResultsController performFetch:&error];
if (! fetchSuccessful) {
[BMWCenterViewController showGhostAlert:error];
}
return _fetchedResultsController;
}
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"deleted = NO OR deleted = NIL"]];
As you see from here, the predicate is set all fine.
It all works when on the second launch of the application, but on first launch it just gives me ALL objects that I receive from JSON ignoring my predicate. When I log the objects in cellForRowAtIndexPath the property exists.
Can you please help me with this?