开发者

How to Structure Core Data Entity

开发者 https://www.devze.com 2023-02-19 23:11 出处:网络
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,

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 tha开发者_运维知识库t 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消