How do I set default values on new properties for existing entities after light weight core data migration? How do I set default values on new properties for existing entities after light weight core data migration? ios ios

How do I set default values on new properties for existing entities after light weight core data migration?


I finally figured it out after 6 months.

The attributes that are added to a core data entity have to be marked as non-optional.Only then will the default values be set automatically during lightweight migration for the entities that were created with the old data model.


You need to use setPrimativeValueForKey in awakeFromFetch because the dynamic accessor used by self.propertyName is not yet active.

However, since the default value is not appearing in the first place, that suggest your migration failed in detail. You may need to create a migration map to ensure the migration is completely successful.


matomo