Dennis
Dennis

Reputation: 714

core data array as attribute

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.

Upvotes: 2

Views: 461

Answers (1)

Mundi
Mundi

Reputation: 80265

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.

Upvotes: 1

Related Questions