• 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: How to create subentity object inheriting from superentity object in core data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: How to create subentity object inheriting from superentity object in core data


  • Subject: re: How to create subentity object inheriting from superentity object in core data
  • From: Ben Trumbull <email@hidden>
  • Date: Wed, 16 Sep 2009 22:09:20 -0700

I've got a generalization in my core data model with entities named A,
B, C let's say where A is a super class with subentities B and C.

A is not abstract, so if I create an A NSManagedObject, I need to
create and relate a single B or C subclass object. How do I make this
happen? I can create the entities, but HOW do I tell the model that
object B is a subclass of object A (or vice versa?)

Note: I did create the model programmatically and the subentities have
been set properly for entity description "A".

Here's my sad attempt to move forward.  As you can see, I've created
the objects I need, but B doesn't know that A is it's superclass
object.  What to do?

Model the entity inheritance in the modeling tool is the easiest approach. If you need to customize your model beyond that at runtime, you can make minor alterations programmatically by loading it and mutating it before creating your NSPersistentStoreCoordinator. If you programmatically create a model, you'll need to add all the super entity's properties to each of the subentities. The programmatic structure is much flatter than it would appear in the graphic Xcode tool. There's no "calling super" in entity inheritance.


You'll need to set the objective-c class names for each entity. The objective-c class must be either the same as the super entity's class or a subclass of that super entity's objective-c class. You cannot create a random mapping of Objective-C classes to entity inheritance.

- Ben

_______________________________________________

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


  • Prev by Date: Re: NSString vs. encoding
  • Next by Date: Re: NSString vs. encoding
  • Previous by thread: Document Attributes into Pdf
  • Next by thread: Re: How to create subentity object inheriting from superentity object in core data
  • Index(es):
    • Date
    • Thread