NSFetchedResultsController crashes on objectAtIndexPath?

后端 未结 2 1366
自闭症患者
自闭症患者 2021-01-28 22:14

I\'m getting a crash when trying to access an object in NSFetchedResultsController.

2013-11-10 15:15:06.568 Social[11503:70b] CoreData: error: Serio         


        
2条回答
  •  盖世英雄少女心
    2021-01-28 22:39

    In one of my NSManagedObject subclasses I had the follwiing code which was causing the issue. NSSets are automatically initialized on NSManagedObejcts and there is no need to initialize them.

    - (void)awakeFromFetch
    {
        if (!self.comments)
            self.comments = [NSMutableSet set];
    
        if (!self.medias)
            self.medias = [NSMutableSet set];
    }
    

    Another problem was that during insert indexPath is null, I had to use newIndexPath instead

    case NSFetchedResultsChangeInsert:
        [self.tableView insertRowsAtIndexPaths:@[newIndexPath]
                              withRowAnimation:UITableViewRowAnimationAutomatic];
        break;
    

提交回复
热议问题