I’m currently planning (and part coding) a new app. I have an array of items which the user creates. This is effectively the library. It’s easiest to think of this as the classic ingredients and meal.
I have a library of ingredients.
I then have a library of meals.
Each meal will contain several ingredients.
So the relationship is one meal to many ingredients. Each ingredient can be used in multiple meals.
I am OK setting all this up – but I am having a think about how the ingredients will be identified within the meal. If I delete an ingredient, I then want to delete the reference in each meal where it may appear.
Should I be assigning a random ID (maybe a 5 digit number) for each ingredient the user creates, then when they add this to a meal, I use the 5 digit ID as the identifier. When a user deletes an ingredient, I then loop through each meal array and remove any references to the said ingredient 5 digit code.
OR… am I completely over thinking this?!
Thanks for any help!!
Just do an: [item hash]
But…
It sounds like you want to just create an array of references from your “meals” to your “ingredients”. An NSArray or NSMutableArray will retain your “ingredient” – and will release it when the array is released.