Reputation: 5586
I have a Bet
object managed by coredata in an iphone app I am developing.
I would like to add a UID (betnum) attribute to this bet object so in the future I can push the bets to a server using this UID to know if it already exists on the server from a previous push. I understand that this is going to involve me updating the version of the iPhone app, adding this attribute to the Bet
class and setting this attribute to an incremented value for all Bet
objects already managed by core data from the previous version (as well as any new ones).
For this I need to migrate the object model using either Lightweight Migration or by creating my own Mapping Model. I have read that I should use the Lightweight Migration where possible because creating my own Mapping Model can get messy. I know it is possible to use Lightweight Migration to add an attribute to an existing object but I don't know about setting specific values by auto-incrementing or something similar.
Can I use Lightweight Migration for this? Do I use Lightweight Migration and then set the values in the code after the migration using some sort of after migration hook or onAppUpdate method? Or am I destined to create my own Mapping Model?
Upvotes: 0
Views: 219
Reputation: 70976
No, you can't use lightweight migration for this, or at least not without some extra work after the fact. Lightweight migration works if you're just adding an attribute, but it doesn't include setting values for the new attribute. You can either (a) use one of the other migration schemes and add your UID values during migration, or (b) use lightweight migration but add a post-processing step where you run through the data store and set up the new values.
Also, keep in mind that Core Data doesn't have auto-incrementing values. You'll have to work out what the value needs to be for each instance.
Upvotes: 1