Core Data Migration: Custom policy in Entity Mapping for the case where App name contains a space

I am trying to add a custom policy to Entity Mapping and it refuses to work because the app name has a space in it. I tried replacing the space character with underscore and hyphen but it still does not work.

I tried creating an MVP where app name did not have any space and it worked in the first try. However, for another MVP where app name had a space in it, it is not working at all.

Answered by DTS Engineer in 824249022

The custom policy name you put in the Core Data model is the name of your custom policy class (NSEntityMigrationPolicy), and a space isn't allowed in a class name. I don't expect that a underscore doesn't work, but a custom policy name isn't tied to the app name, and so you can just choose a name that works for you.

More importantly, I’d like to be clear that using custom mapping models is now discouraged, as BenT mentioned in this DevForum post:

You should basically only use lightweight migration with an inferred mapping model. You should avoid your own custom mapping models and migration managers as these require an unbounded amount of memory.

When having something that the inferred mapping model doesn't work, consider decomposing the migration into multiple stages, and then do a staged migration, as discussed in the following WWDC session:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

The custom policy name you put in the Core Data model is the name of your custom policy class (NSEntityMigrationPolicy), and a space isn't allowed in a class name. I don't expect that a underscore doesn't work, but a custom policy name isn't tied to the app name, and so you can just choose a name that works for you.

More importantly, I’d like to be clear that using custom mapping models is now discouraged, as BenT mentioned in this DevForum post:

You should basically only use lightweight migration with an inferred mapping model. You should avoid your own custom mapping models and migration managers as these require an unbounded amount of memory.

When having something that the inferred mapping model doesn't work, consider decomposing the migration into multiple stages, and then do a staged migration, as discussed in the following WWDC session:

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

and a space isn't allowed in a class name.

The space is in the App name not in the class name.


Thanks for the additional information about staged migrations. Will check them out.

Also, I just checked Staged Migrations. It supports macOS 14 and onwards.

The space is in the App name not in the class name.

I thought it was the custom policy name, as shown in your screenshot. Sorry for that.

It will be really strange to me if you meant a space in your app name leading to an issue in your custom policy. If you can provide a minimal project that contains only the code relevant to the issue, I'd be interested in taking a look.

Also, I just checked Staged Migrations. It supports macOS 14 and onwards.

That's correct.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Core Data Migration: Custom policy in Entity Mapping for the case where App name contains a space
 
 
Q