I am getting a '-[_SwiftValue mergeType]: unrecognized selector sent to instance' error whenever I try to save a managed object context after doing a delete or an update of a record. For example:
context.delete(managedObject)
follow by
context.save()
and yes, context.save() is in a do-try-catch.
Records insert just fine, but the delete is throwing an exception. Stack trace is as follows:
*** 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
Trace starts right after it leaves my code.
Any insight would be helpful.
You may get this error when you use code like this, to set a merge policy:
context.mergePolicy = NSMergePolicyType.mergeByPropertyStoreTrumpMergePolicyType
Instead use this:
context.mergePolicy = NSMergePolicy(merge: .mergeByPropertyStoreTrumpMergePolicyType)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With