Re: Programmatically providing default value for new core data attribute?
Re: Programmatically providing default value for new core data attribute?
- Subject: Re: Programmatically providing default value for new core data attribute?
- From: Dave Fernandes <email@hidden>
- Date: Wed, 31 Oct 2012 12:20:44 -0400
[resent to list-serve]
You can create a subclass of NSEntityMigrationPolicy, then specify this class in the Custom Policy for that entity in your mapping model. During migration, the createDestinationInstancesForSourceInstance:::: method of your migration policy class will be called, and can fill in the value for the new attribute.
Note that the object you will get to work with will be a generic NSManagedObject, and not any subclass you have defined for that entity. So if you need your subclass methods, or if you need to access other entities, and not just the one you are handed, you will need to do that AFTER migration has completed.
Dave
On 2012-10-31, at 5:44 AM, Rick Mann <email@hidden> wrote:
> Hi. I've added a simple attribute to my model that should be a concatenation of a handful of other attributes, run through some code. I don't suppose there's any way to do the lightweight migration but tell it, "here's a method to call to get the default value of this property?"
>
> I looked at doing a mapping model, but even that just has me build the value in there; no apparent way to run it through my code.
>
> Given that, I can let lightweight migration do its thing, then post-process it, but I don't see a way to determine that lightweight migration ran when I opened the store.
>
> Any suggestions? Will -isConfiguration:compatibleWithStoreMetadata: tell me a lightweight migration-capable change is incompatible?
It tells you whether or not a migration is needed (lightweight or otherwise).
>
> Thanks,
>
> --
> Rick
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden