Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3: -[_SwiftValue mergeType]: unrecognized selector sent to instance

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.

like image 565
jslicari Avatar asked Mar 10 '23 16:03

jslicari


1 Answers

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)
like image 107
Ely Avatar answered Apr 28 '23 20:04

Ely