I am displaying several tasks of a list of activities. To achieve this I am using NSPredicate predicateWithFormat: to select the items of the list. But the problem I have is regarding previously deleted tasks of that list. Even though they are not displayed (or I should say displayed as void), they are still counted.
So my question is: How can I only select items (tasks) that are still part of the list? Deleted data should be left out. They should completely be removed actually.
Part of my code (I have just updated it following Martin's comment):
- (void)continueAutomaticModeWithList:(DIDList *)list taskIndex:(NSInteger)index {
if (index == list.tasks.count) return;
DIDTask *task = [DIDTask MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"list == %@ && index == %@", list, @(index)]];
if (task.completedValue) {
[self continueAutomaticModeWithList:list taskIndex:index + 1];
return;
}
[UIAlertView showAlertViewWithTitle:@"Task" message:task.name cancelButtonTitle:@"Stop" otherButtonTitles:@[@"Click to go to next action", @"Click to go to next action and notify user"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
if (buttonIndex > 0) {
[MagicalRecord saveWithBlock:^(NSManagedObjectContext localContext) {
[[task MR_inContext:localContext] setCompletedValue:buttonIndex == 1];
} completion:^(BOOL success, NSError *error) {
[self.tableView reloadData];
}];
[self continueAutomaticModeWithList:list taskIndex:index 1];
}
}];
}
index
attribute of the remaining objects. If you search forindex == 1
and that object has been deleted, then you will getnil
, not the next undeleted object. – Martin R