user594161
user594161

Reputation:

How to Structure Core Data Entity

I want to make an entity for a workout Routine.

I'll name the entity "Routine". The user is prompted with a UIAlert with text prompt to enter a name for each of the days (for example 1) chest day, 2) back day, 3) legs day, etc.). And within each of these days will be a list of exercises they choose to be done that day.

I have all the exercises stored in a dictionary within a .plist right now.

I need help structuring the attributes, etc for Routines.

I'm thinking having an attribute for Day (where they name the day) and then thats where I'm stuck. I would assume to use a dictionary or an array to hold that day's exercises but this can't be done in Core Data.

Upvotes: 0

Views: 184

Answers (1)

Matthew Frederick
Matthew Frederick

Reputation: 22305

Don't think in terms of dictionaries or array, think in terms of objects. The things you're thinking of putting in your dict/array are an actual exercise being performed as part of a day's routine, right? So you need an internal name for that; "exercise" doesn't really work because that's the description of the thing you do, not the doing, and "rep" is just one. Edit: You've used the word "Set," which makes sense, so I'll use that too.

So your data model might look like:

Day <----->> Set

where < is a "to one" relationship and >> is a "to many" relationship. That's how you get arrays and dictionaries, effectively, by understanding that there's one object that has a relationship to multiple copies of another object.

Upvotes: 1

Related Questions