• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data: insertNewObjectForEntityForName doesn't return my custom subclass during migration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: insertNewObjectForEntityForName doesn't return my custom subclass during migration


  • Subject: Re: Core Data: insertNewObjectForEntityForName doesn't return my custom subclass during migration
  • From: "Melissa J. Turner" <email@hidden>
  • Date: Thu, 3 Dec 2009 13:22:48 -0800

On Dec 3, 2009, at 09:08, Sean McBride wrote:

> Hi all,
>
> The docs for NSEntityDescription say
> "initWithEntity:insertIntoManagedObjectContext: returns an instance of
> the appropriate class for the entity".
>
> This seems to be mostly true.  Yet when I do:
>
> [NSEntityDescription insertNewObjectForEntityForName:@"FooBar"
> inManagedObjectContext:moc];
>
> it's giving me an NSManagedObject not an RRFooBar.  I've confirmed that
> by sending the class method and also sending message that only my
> subclass responds to.  I've confirmed that my xcdatamodel has specified
> the right subclass (RRFooBar).
>
> This happens only during migration (the same code gives RRFooBar if
> migration is not involved).  Specifically during this partial backtrace:
>
> ...
> -[NSEntityMigrationPolicy createRelat
> ionshipsForDestinationInstance:entityMapping:manager:error:]
> -[NSMigrationManager(InternalMethods) _doSecondPassForMapping:error:]
> -[NSMigrationManager migrateStoreFrom
> URL:type:options:withMappingModel:toD
> estinationURL:destinationType:destinationOptions:error:]
> ...
>
> Is this expected?
>

This is expected.

During migration, Core Data uses NSManagedObject instead of custom subclasses to contain object data. This is to avoid triggering application logic and/or validation rules in the classes during what should be a pure data transformation step.  Any logic you need during migration should be encoded into the mapping model.

+Melissa

_______________________________________________

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

References: 
 >Core Data: insertNewObjectForEntityForName doesn't return my custom subclass during migration (From: "Sean McBride" <email@hidden>)

  • Prev by Date: re: NSSpellChecker and checkSpellingOfString problems
  • Next by Date: Making NSFetchedResultsController register changes to the entity's relationship, not just attributes
  • Previous by thread: Core Data: insertNewObjectForEntityForName doesn't return my custom subclass during migration
  • Next by thread: MacResearch Tutorial on beginning a Cocoa/iPhone app.
  • Index(es):
    • Date
    • Thread