I am trying to implement very basic migration using Core Data. The only property was originally created as Integer 16 with values 0 or 1. In the new version of the model, this property was changed to Boolean , and the migration policy below should handle it. I saw several examples written in Swift and they don't seem to make access open / open or add @objc to make it accessible to Objective-C. I did this to eliminate any reason why it does not work.
I created a user policy mapping model to map an entity to the following expression.
FUNCTION($entityPolicy, "convertInteger:" , $source.active)
It continues to fail because the selector is not recognized. In particular, he gets the following error.
unrecognized selector sent to instance
I have tried many options.
- convertInteger:
- Convert (integer :)
- convertInteger (_ :)
I cannot get any changes to work. What is a valid selector for this expression?
In Swift code, I put the statement in the initializer and it passes, but I cannot use the same selector in the expression for the policy.
import CoreData @objc open class IntegerToBooleanMigrationPolicy: NSEntityMigrationPolicy { @objc public override init() { super.init() assert(responds(to: #selector(convert(integer:))), "Policy does not respond to selector!") } @objc open func convert(integer: Int16) -> Bool { debugPrint("Converting \(integer) to boolean") return integer == 1 } }
source share