Changing the master data attribute type from Integer32 to String

I considered lightweight migration before, and also compared the main changes, but I googled and crowded and did not find a similar case where the name of the object remains unchanged, but the type of the attribute changes from int (I would have thought it would be easy to do)

It seemed to me that I was on the right path, subclassing NSEntityMigrationPolicy, then I set the custom policy field in mapmodel to this subclass (it did not autocomplete even after restarting Xcode ...)

enter image description here

but I see that createDestinationInstancesForSourceInstance does not receive the call enter image description here

Now, since I'm dealing with a custom mapping model and policy, do I still have to output the mapping model, but with Migrate automatically disabled in persistent storage?

NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@NO,
                          NSInferMappingModelAutomaticallyOption:@YES};

!

" ", - $source.incrementer.string:)

Current mapping

+4
2

, ( Apple),

Xcode 7.1:

1. :

  • .xcdatamodeldEditorAdd model version ...
  • attribute type
  • ( ). , .

Current model

2.

  • New file -> Mapping Model ( → )
  • source ( ) target ( ) .
  • , : NameToName. , : FUNCTION($entityPolicy, "<*transformingMethodName*>" , $source.<*attributeName*>)

- transformingMethodName: , . ( - )

- attributeName:

  1. <*EntityName*>TransformationPolicy NSEntityMigrationPolicy
  2. transformingMethodName, . ( , , ). , ,
  3. (Model.xcmappingmodel → File inspector → third column → Custom policy → TransformationPolicy.)

Register migration policy class

+5

, , ? SQLite, , int varchar .

, , Core Data . .

, , , -createDestinationInstancesForSourceInstance..., , . , . , , , .

, - . , . , - (, " " ):

  • string
    • , int ;
    • , , , , , ( ) int .

, . , . . iOS . .

+3

Source: https://habr.com/ru/post/1535083/


All Articles