Reputation: 11899
I am quite new to core data I have read a couple of articles on Apples dev site & now am somewhat confortable with using it with one entity.
Now I am working on an app that recommends recipes to users.
The datadesign is somewhat like this I have these entities
Item
,
Pantry
&
Recipe
.
Relations are as follows:
Item to many Pantry
Item to many Recipe
The logic is to get items from pantry & compare them with values in recipe & then suggest user a recipe.
I am a little confused on how to go about it. Is my datadesign okay. How do I need to change it if in case ..? & will accessing pantry objects managed instance automatically fetch respective item from Items table ...? & likewise will pantry be fetched when I access recipe...?
comments, suggestions, pointers to coredata learning resources will be highly appreciated.
Thanks
Upvotes: 0
Views: 303
Reputation: 64428
Your data model should reflect the real-world object, events or conditions you are trying to simulate.
In this case it sounds like you are simulating a kitchen with a single pantry, numerous items in the pantry and then a book of recipes that uses the items. So, in pseudocode, your object model should look something like:
Item{
pantry<<-->Pantry.items
recipies<<-->>Recipie.items
}
Pantry{
items<->>Item.pantry
}
Recipe{
items<<-->>Recipie
}
Note that the items to recipe relationship is to-many and to-many because the same item can show up in many recipes and many different recipes can use the same items.
Upvotes: 1
Reputation: 907
You can take a look at an example (iPhoneCoreDataRecipes) from the Apple site. They are also storing and referencing the recipe data in Core Data.
Upvotes: 1