You cannot use lightweight migration for this so it is a little bit harder (thanks Apple), but not impossible
step by step in Xcode 7.1:
1. Create the new model version:
- Select your
.xcdatamodeld
model ->Editor
->Add model version ...
- Edit the new model's entity's
attribute type
- Change current model version to the new one (File inspector). You should see the green tick mark moved.
2. Custom Core Data mapping model
New file -> Mapping Model
(Core Data -> Mapping Model)- Choose the
source
(from model) andtarget
(to model) version of your model - The custom mapping model contains entities mappings called this way:
NameToName
. Change value expression of the changed attribute in target entity in this file reflect the one you need to:FUNCTION($entityPolicy, "<*transformingMethodName*>" , $source.<*attributeName*>)
- transformingMethodName: Your custom method that will be called to transform attribute type. (Will define it in the next step - hold on)
- attributeName: your changed attribute name
- Create
<*EntityName*>TransformationPolicy
class as a subclass ofNSEntityMigrationPolicy
- Implement
transformingMethodName
you defined above. (Do what you need there to change the attribute type). Make sure you added this method to your header file as well - Register this class as custom entity migration policy in the mapping model (Model.xcmappingmodel -> File inspector -> third column -> Custom policy -> Enter the name of your TransformationPolicy class.)