【发布时间】:2019-10-29 15:16:32
【问题描述】:
在 macOS 应用程序上,我有一个简单的AddEditViewController,它从主视图控制器接收 NSManagedObject。
然后,我创建一个子 NSManagedObjectContext,以便在用户按下取消按钮时轻松恢复更改。
这里是ViewWillAppear()的实现
super.viewWillAppear()
// Create child MOC
self.managedObjectContext = NSManagedObjectContext(concurrencyType: self.parentManagedObjectContext.concurrencyType)
self.managedObjectContext.parent = self.parentManagedObjectContext
但这给了我以下错误:
[General] Parent NSManagedObjectContext must use either NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType.
0 CoreFoundation 0x00007fff379aad63 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6d899bd4 objc_exception_throw + 48
2 CoreData 0x00007fff3743676e -[NSManagedObjectContext setParentContext:] + 334
3 Zacc 0x00000001000714fa $s4MyApp28AddEditViewControllerC14viewWillAppearyyF + 666
对这里的问题有任何想法吗?我在网上找不到任何东西。
我在 macOS 10.15 上使用 Xcode 11。
感谢您的帮助!
【问题讨论】: