2

I want create attribute of "event" entity that will have a short list of events what the correct way to make it? I think the right way is just use array but how can I do it? if someone can give me code example it will be nice.

Dennis
  • 704
  • 1
  • 9
  • 25
  • create one more entity named as `ShortEvent` & use it to point from the original entity `Event` using primary key & foreign key mechanism. – hp iOS Coder Dec 04 '12 at 12:01
  • core data is something new for me, I don't understand what you try to tell me can you explain how to use primary key? or link me to tutorial? also I am not sure you understand me as well, I have entity PERSON that will have relation to EVENT that will have type(attribute) when user create new EVENT I just want that he be able choose the type of the event from list (not insert by him self just choose) how do it? – Dennis Dec 04 '12 at 15:10

1 Answers1

1

Don't listen to any advice regarding foreign keys - they do not exist in Core Data. What you have to do is link your Event entity to another (or itself) with a relationship.

It is not clear why an event would have a short list of events. Maybe you want to distinguish event types or something similar. You could then create a new entity EventType and establish a to-many relationship in the Core Data Model Editor:

Event <<----->> EventType

Now an event could be linked an arbitrary number of EventType objects. You could use a relationship name like allowedEventTypes for each event and access this set (not an array, mind you, but an NSSet with unordered unique objects):

NSSet *types = event.allowedEventTypes;

Once you master the core data modeling technique, the coding becomes exceedingly simple.

Mundi
  • 79,884
  • 17
  • 117
  • 140