简体   繁体   中英

enumeration values 'NSFetchedResultsChangeMove' and NSFetchedResultsChangeUpdate' not handled in switch

I get this warning: enumeration values 'NSFetchedResultsChangeMove' and NSFetchedResultsChangeUpdate' not handled in switch

Any ideas?

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView endUpdates];
}

thanks in advance

You can also add

        default:
        break;

to get rid of those warnings.

The compiler knows that NSFetchedResultsChangeType has four possible values, but your code only handles two of those. If you know for sure that the other two will not occur, you can ignore the warning. But it would be safest to include some code to handle these other values, either nothing or an NSLog to see if they do occur. I would add

case NSFetchedResultsChangeMove:
    NSLog(@"A table item was moved");
    break;
case NSFetchedResultsChangeUpdate:
    NSLog(@"A table item was updated");
    break;

into your switch statement. EDIT: having checked the docs, I see that these two values are not used for Section changes, so you can either ignore the warning or add null case statements along the above lines to suppress the warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM