If I understand you problem correctly, the following should work:
- (void)continueAutomaticModeWithList:(DIDList *)list taskIndex:(NSInteger)index {
if (index == list.tasks.count) return;
DIDTask *task = [DIDTask MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"list == %@ && index >= %@", list, @(index)]
sortedBy:@"index"
ascending:YES];
if (task == nil) {
// No task with given or greater index found.
return;
}
if (task.completedValue) {
[self continueAutomaticModeWithList:list taskIndex:task.index + 1];
return;
}
// ...
}
Instead of searching for an object with the given index (which might not exist anymore), it searches for the "first" object which has at least the given index.