Programmatically providing default value for new core data attribute?
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? Thanks, -- Rick ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Programmatically providing default value for new core data attribute?
[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 rm...@latencyzero.com 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/dave.fernandes%40utoronto.ca This email sent to dave.fernan...@utoronto.ca ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Programmatically providing default value for new core data attribute?
On 2012 Oct 31, at 02:44, Rick Mann rm...@latencyzero.com wrote: Will -isConfiguration:compatibleWithStoreMetadata: tell me a lightweight migration-capable change is incompatible? I think all it does is compare UUIDs or hashes, so the answer is no. 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. Any suggestions? You put this code in a subclass of NSMigrationPolicy. It is not difficult, and a useful thing to learn. I prefer non-lightweight migration, because migrating users' data is risky. When I write the expressions and/or code myself, I can understand, probe, and test it fully. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com