CoreData: error: Serious application error. Exception was caught during Core Data change processing

接手的项目,报错如下:


2016-10-14 10:38:05.757 XXX[8734:4036919] CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  -[__NSCFSet addObject:]: attempt to insert nil with userInfo (null)

2016-10-14 10:38:05.758 XXX[8734:4036919] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet addObject:]: attempt to insert nil'

*** First throw call stack:

(0x185710f48 0x19abbbf80 0x185710e90 0x185635b28 0x1853e4308 0x1853e2fec 0x1853ee17c 0x1853e1e7c 0x100180530 0x1001825b4 0x100237cb8 0x1001159f8 0x1002b3760 0x1002ac104 0x1002b35cc 0x1001a67cc 0x184e1b510 0x184e2dff4 0x186638374 0x18658b1a0 0x18657b3e8 0x18663a768 0x100e71c68 0x100e7e780 0x100e75958 0x100e80898 0x100e80590 0x19b5e1470 0x19b5e1020)


折腾了一段时间,原来是多个网络请求同时返回时候,造成存储coredata错误。果然,数据库问题多出在同步访问上。使用这个吧。

/* synchronously performs the block on the context's queue.  May safely be called reentrantly.  */

    @available(iOS 5.0, *)

    public func performBlockAndWait(block: () -> Void)

你可能感兴趣的:(ios,swift)