On 2013 Mar 04, at 14:38, Sean McBride <s...@rogue-research.com> wrote:
> What's a good way to delete some managed objects from a store when migrating > the store from version x to version y? Basically, for entity 'Foo', I'd like > for instances that match predicate 'bar' to not exist in the new store. This is easy to do with a mapping model, migration policy and migration manager. In your NSMigrationManager subclass implementation, implement an override something like this⦠- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject*)oldInstance entityMapping:(NSEntityMapping*)inMapping manager:(NSMigrationManager*)inManager error:(NSError**)error_p { BOOL ok = YES ; NSError* error = nil ; NSEntityDescription *sourceInstanceEntity = [oldInstance entity] ; NSString* sourceInstanceEntityName = [sourceInstanceEntity name] ; if ([sourceInstanceEntityName isEqualToString:constEntityNameStark]) { // Here's your predicate⦠if ([oldInstance valueForKey:constKeyWhatever] passes the predicate) { ok = [super createDestinationInstancesForSourceInstance:oldInstance entityMapping:inMapping manager:inManager error:&error] ; } else { // Don't want this object in the new store. Do nothing! } } if (error && error_p) { *error_p = error ; } return ok ; } You can tweak destination instances by getting with -destinationInstancesForEntityMappingNamed:sourceInstances:. But be careful to send only NSManagedObject messages to the source and destination instances. Although you think of them as your old MyBazManagedObject, remember they're not. Don't use -myProperty. Use -valueForKey:@"myProperty". You can literally re-make your whole data model by subclassing NSMigrationManager. Merge entities, make new relationships, whatever your marketing department desires :) _______________________________________________ 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