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.

2
  • create one more entity named as ShortEvent & use it to point from the original entity Event using primary key & foreign key mechanism. Commented Dec 4, 2012 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? Commented Dec 4, 2012 at 15:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.