每当我在删除或更新记录后尝试保存托管对象上下文时,都会收到“-[_ SwiftValue mergeType]:无法识别的选择器发送到实例”错误。例如:
context.delete(managedObject)
遵从
context.save()
是的,context.save()处于do-try-catch中。
记录插入就好了,但是删除引发了异常。堆栈跟踪如下:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue mergeType]: unrecognized selector sent to instance 0x60800005b0f0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010afac34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010a5f021e objc_exception_throw + 48
2 CoreFoundation 0x000000010b01bf34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010af31c15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010af31798 _CF_forwarding_prep_0 + 120
5 CoreData 0x000000010aae203a -[NSManagedObjectContext(_NSInternalAdditions) _validateObjects:forOperation:error:exhaustive:forSave:] + 1946
6 CoreData 0x000000010aae1836 -[NSManagedObjectContext(_NSInternalAdditions) _validateChangesForSave:] + 422
7 CoreData 0x000000010aae1476 -[NSManagedObjectContext(_NSInternalChangeProcessing) _prepareForPushChanges:] + 214
8 CoreData 0x000000010aaddeb2 -[NSManagedObjectContext save:] + 562
跟踪在离开我的代码后立即开始。
任何见解都会有所帮助。
最佳答案
当您使用如下代码来设置合并策略时,可能会出现以下错误:
context.mergePolicy = NSMergePolicyType.mergeByPropertyStoreTrumpMergePolicyType
而是使用此:
context.mergePolicy = NSMergePolicy(merge: .mergeByPropertyStoreTrumpMergePolicyType)
关于ios - Swift 3:-[_ SwiftValue mergeType]:无法识别的选择器已发送到实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40554616/