I have a question about some foundational designing of coredata to make it future proof for my app!
Heres the scenario, lets consider im developing a coredata model to track Body mass index, (BMI), which is just one example and it will be listed in an entity named: Category.
Category has the following attributes:
- NSString(String)Title (Weight)
- NSNumber(float) upperMax (100) *
- NSNumber(float) lowerMax (40) *
*Note: Those upper and lower limits are completely hypothetical and have no scientific basis at all, im just using it for my example! ahem..
Another Entity : "Tracker"
- NSDate timeStamp
- NSNumber entry
to-many relationship exists here - Category<--->>Tracker
.
Uptil here, everything is well understood. The user enters inserts the tracker with the timeStamp and enters the value(current recorded weight), the application then compares if its above or below or between(normal) the preset values in category.
What If I add another category - Body mass index (BMI). BMI compares weight to height.
I can easily add them as a new cateogry in Entity as:
- Name BMI
- UpperMax 23.5
- LowerMax 18.5
and user will add the track entries that compares the two.
But I want to be able to add weight AND height and not the BMI index it self, this creates a scenario where the user will enter values to two textfields.
the most obvious answer was to add another entry in Category called "Height", but then I'd have to create a new one to relate that with BMI.
Instead, im wondering about a new approach to design the cateogory entity in such a way that the Entry values can be user specified. eg. ( the Weight in "Weight") = required textfield input is ONE eg2. (weight and height in "BMI") = required textfield input is TWO.
Maybe i should create a new entity? with the name "fields" and store the category and specify the normal values number of required fields in this new entity.
Its pretty vague right now hope you get the idea of what im asking.
FROM A user's perspective: I want to be able to add "customised" categories in the app at runtime itself. Like in creating a "new" category, I'll add the Name and Add fields to the category using "add" button in the tableView.
In BMI, I'll add two fields Name: 1-Weight UpperMax/LowerMax etc. 2-Height etc..
Then when I tap "new Entrys to track growth" Two textFields should appear based on the count of Category.fields (relationship).
Is this the right approach? and how should i be connecting the "Category" entity with the "Entry" entity. I got "Fields" entity somewhere in the middle