CoreData mapping two different objects to same entity?
CoreData mapping two different objects to same entity?
- Subject: CoreData mapping two different objects to same entity?
- From: William Squires <email@hidden>
- Date: Sun, 15 May 2011 20:01:56 -0500
Is it possible to map two different objects (the ivars are the same, just some validation methods are different) to the same entity?
Here's what I have:
I want to make a view in which the player 'rolls up' a new player-character. This object has certain ivars (and @property declarations) that map to the entity in the .xcdatamodel file. The actual accessors, however, are hand-coded to allow certain restrictions to be relaxed while the PC is being created. Another object will also have the same (name and number) of ivars and also map to the entity, but it's accessors have more restrictions as to what can be written to. Example:
@property (readwrite, assign, nonatomic) UInt32 hitPoints;
@property (readwrite, assign, nonatomic) UInt32 maxHitPoints;
in the object used in the 'roll-up-the-new-PC-window' view, but is:
@property (readwrite, assign, nonatomic) UInt32 hitPoints;
@property (readonly, nonatomic) UInt32 maxHitPoints;
in the game runtime - i.e. a different method is used (when leveling up) to re-set the new maximum hit points value.
After creation, the new PC will be saved, then a new object of the second (more restrictive) class will be created, and mapped to the entity, then loaded.
Is this reasonable with CoreData, or should I just utilize an XML file solely for storing the PC info? The reason I want to use CoreData is that the player-character object can 'contain' (reference) one or more 'inventory' objects which themselves may be 'containers' (in the game sense) that also reference other inventory object. For example, the player may have a magic 'bag of holding' that itself contains 2 GP, a red gem, and a gold ring. Each of these are also inventory objects, and so the whole thing makes an object graph; just what CoreData is good for.
_______________________________________________
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