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.
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:
-
Evolve your Core Data schema (starting at 7:20).
-
What’s new in Core Data (The “Stage your migrations” section starting at 06:31).
Best,
——
Ziqiao Chen
Worldwide Developer Relations.