0

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.

1 Answers1

1

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.

Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • Thanks Matt that makes sense and I'm going to start thinking of my data as objects. It will take some getting used to, however. The thing thats confusing me is that the user will be entering a different number of sets/ reps etc per exercise depending on what they perform. So should I have separate entities for set, rep, exercise, and routine? Or Do I need to break it down even further. –  Mar 28 '11 at 05:46
  • 1
    A rep is just one part of a set, right, merely a count? One Set might be 10 reps, another Set is 20 reps, depending on the exercise? Since it's just a count, there's no reason to make it an object, it can be a property of an instance of a Set. Remember that the definition of each object has properties & relationships to other objects, but that each *instance* of an object has its own specific property values and specific relationships. As a result, one instance of Exercise might have 3 related Sets (each of which has a property value with the number of reps), while another has 5 related Sets. – Matthew Frederick Mar 28 '11 at 12:11
  • Thanks Matt, so if I make set an entity, I can make properties for "set" and "weight". So one set may have "rep = 5" and "weight = 200lb". My question is, each set will be for a particular exercise type. Like bench press will have 4 different sets. So the exercise would be a different entity with a to many relationship to sets? –  Mar 28 '11 at 15:44
  • @Faisal I think you mean "reps" and "weight," and yeah, that makes sense. And yes, Exercise is sort of a category, so it would be its own object (just as it would be a lookup table in a database). It might only have one property, its name, but it might have other properties, too, like a description. – Matthew Frederick Mar 28 '11 at 16:25
  • @Faisal One thing I'll caution against in general is the idea that the objects in the store must perfectly match the real world. In reality they should be related to their actual use: when first doing this sometimes folks create overly-complex data structures. A "Rep" object would be overkill, for instance, because it would have no properties or methods. If you find that all you ever do with an object is count it, it likely doesn't need to be an actual object. (If you summed or averaged it, though, it is storing a value of some kind and so should likely exist.) You're doing great so far. – Matthew Frederick Mar 28 '11 at 16:30
  • @Matthew, thanks for the advice. It is slowly coming together and your suggestions are really helping. And yes I meant "rep", not "set", sorry. I'm going to restructure the Data Model tonight from what we discussed here. One other thing though, I have another question relating to actually fetching and saving an entity here if you wouldn't mind checking it out. Thanks. http://stackoverflow.com/questions/5454354/tableview-crashing-freezing-because-of-core-data-error –  Mar 28 '11 at 16:40