Xcode 7 beta 6和NSFetchedResultsController今天让我很头疼.如果我使用Xcode 6编译相同的(使用Swift 2修复)代码,程序可以在设备和模拟器(iOS 7,iOS8)上运行.但是,如果我使用Xcode 7 beta 6进行编译,则只要我更新Core Data,程序就会在设备(iOS 8.4)上崩溃,并显示以下错误消息.
我得到类似于下面的错误
CoreData:错误:严重的应用程序错误.在调用-controllerDidChangeContent:期间,从NSFetchedResultsController的委托中捕获到异常.无效更新:第0节中的行数无效.更新(2)后现有部分中包含的行数必须等于更新前该部分中包含的行数(2),加上或减去数字从该部分插入或删除的行(插入2个,删除1个)并加上或减去移入或移出该部分的行数(0移入,0移出).用户信息(null)
有时它会因为另一个错误而崩溃
从空闲列表中出列的无效指针***在malloc_error_break中设置断点以进行调试
//NSFetchedResultsController delegates
func controllerWillChangeContent(controller: NSFetchedResultsController) {
    self.tableView.beginUpdates()
}
func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
    switch type {
    case .Insert:
        self.tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
    case .Delete:
        self.tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
    default:
        return
    }
}
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
    switch type {
    case .Insert:
        print("Insert New: \(newIndexPath) Old: …我们有两个可选的NSArrays.目标是检查它们是否相等.我的解决方案是
func isArrayEqualToArray(array1:NSArray?, array2:NSArray?) -> Bool {
    let areBothEmpty:Bool = array1 == nil && array2 == nil
    var areBothEqual:Bool
    if !areBothEmpty && array2 != nil {
        areBothEqual = array1?.isEqualToArray(array2!) ?? false
    } else {
        areBothEqual = false
    }
    let result = areBothEqual || areBothEmpty
    return result
}
我觉得它有点过于冗长.它应该以更简洁和可读的方式实现.有没有人有更好的解决方案?