获取核心数据请求时出错

时间:2017-12-22 05:24:50

标签: ios xcode core-data swift3 multipeer-connectivity

我想在核心数据中存储一些新数据。它大部分时间都有效,但它给出了错误

[error] error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  *** Collection <__NSCFSet: 0x16eb6a50> was mutated while being enumerated. with userInfo (null)

CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  *** Collection <__NSCFSet: 0x16eb6a50> was mutated while being enumerated. with userInfo (null)
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFSet: 0x16eb6a50> was mutated while being enumerated.'


*** First throw call stack:

(0x1deefb3d 0x1d177067 0x1deef5e1 0x1fea4bbb 0x1fe8a863 0x1fe89be5 0x1fe68da9 0x9403ec 0x8cefc 0x137ed0 0x134530 0x13790c 0x126ab0 0xd0be0 0xd3a467 0xd3a453 0xd3ed47 0x1deabd69 0x1dea9e19 0x1ddfd1af 0x1ddfcfd1 0x1f5a7b41 0x2317fa53 0x8e068 0x1d5ea4eb)
libc++abi.dylib: terminating with uncaught exception of type NSException

偶尔

以下是AppDelegate中的getData代码

func getData(request: NSFetchRequest<NSManagedObject>) -> Any{
    do {
        let context = persistentContainer.viewContext
        let results = try context.fetch(request)
        return results
    } catch {
        let nserror = error as NSError
        fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
    }
}

我发现它在let results = try context.fetch(request)处中断了。我想知道这条线或其他线是否有任何问题?

有没有人有任何想法?提前致谢

0 个答案:

没有答案