0

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?

Vivienne Fosh
  • 1,751
  • 17
  • 24
  • 1
    Naming an attribute "deleted" causes problems, compare http://stackoverflow.com/questions/16000242/core-data-nspredicate-predicatewithblock-and-predicatewithformat-in-parent-child/16003894#16003894. – Martin R Apr 23 '13 at 21:00
  • You made my coding night. Please make this an answer so that I can choose it an answer :) And you know what's weird: it won't let me create property "isDeleted", but "deleted" is fine for Xcode... – Vivienne Fosh Apr 23 '13 at 21:34
  • And why I actually could filter fetch results with a predicate the second time I launched the application? This is what's weird :) – Vivienne Fosh Apr 23 '13 at 21:47
  • I have no idea, but as demonstrated in the linked answer, "strange things" happen if you call the attribute "deleted", so I would say that it is futile to investigate why it works under some conditions. – Martin R Apr 27 '13 at 04:58

0 Answers0