开发者

unique identifier for array of items in iphone

开发者 https://www.devze.com 2023-01-26 03:28 出处:网络
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 mea

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 relationsh开发者_Python百科ip 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!!


How about just using sqlite for storing both ingredients and meals? Don't know what you are actually coding, but it sounds like a good application for a database.

If you don't need to permanently store the data (e.g. you are actually talking about a game or something), you could still use a db with temporary tables).


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.

0

精彩评论

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