Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AlJaMa

macrumors newbie
Original poster
May 12, 2008
3
0
Hey everyone,
I am trying to wrap my head around a seemingly simple concept. I would like to use CoreData to create a listing of different objects that all spawn from the same parent class. Here is example of my data Schema.
img.png


What I would like to do is create a list of all Events (with just data from the "Event" parent Class) but then when the item is clicked I can display the data that is specific to that child class.

Currently I have the list working, all I need now is a way to determine the type of the subclass of Event. If This is not clear enough, here is how I am running it currently.

Create "partyEvent"
List all "Event" objects
When clicked, show detail of the "PartyEvent" object

What I was thinking is that I could add a "type" to the "Event" class, then just cast accordingly when it is clicked?

Thanks!
AlJaMa
 
Hey everyone,
I am trying to wrap my head around a seemingly simple concept. I would like to use CoreData to create a listing of different objects that all spawn from the same parent class. Here is example of my data Schema.
img.png


What I would like to do is create a list of all Events (with just data from the "Event" parent Class) but then when the item is clicked I can display the data that is specific to that child class.

Currently I have the list working, all I need now is a way to determine the type of the subclass of Event. If This is not clear enough, here is how I am running it currently.

Create "partyEvent"
List all "Event" objects
When clicked, show detail of the "PartyEvent" object

What I was thinking is that I could add a "type" to the "Event" class, then just cast accordingly when it is clicked?

Thanks!
AlJaMa

You don't need to cast. Just use "id". If you have to find out which type it is, get the entitydescription of the managedobject.

(untested code)
Code:
-(void) someMethod {
 id yourEvent = [self getEvent]; //I assume you have an instance somehow.
 NSString *type = [[yourEvent entity] name];
 [yourEvent valueForKey:@"latitude"]; //possible for all events
 if ([type isEqualto:@"PartyEvent"]
     [yourEvent valueForKey:@"extradata"]; //only for some events
}

Maybe you need to go over the structure of your model again. I would make the relationship from event to photo a "to many". Or can you not have multiple photo's for a single event?
 
Thanks

Wow thanks so much, I cant believe that I forgot about id :eek: haha. Anyways, thanks for noticing the error in the data structure too, but I just made that one up real quick as to not over complicate the example.

Thanks again!
AlJaMa
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.