I've been pondering over this problem for a while now but I am not able to get a nice concise efficient solution yet.
Problem:
I have a recipe list which is an NSArray, every recipe object contains ingredients as NSSet objects. Data is one to many relationship & is coming from coredata. Now there is another list an NSArray which contains items(ingredients) a particular person currently have.
Now I have to somehow compare currently present items which user have with ingredients in recipes & recommend user recipes in a table view with sections like all items present, 1 item missing, two items missing and three items missing.
How do you guys think I should approach this problem. I have tried a few things but I end up getting even more lost each time.
Any help/pointers will be highly appreciated
You have interesting methods in NSSet:
+ (id)setWithArray:(NSArray *)array will allow you to quickly convert your array to set.
- (BOOL)isSubsetOfSet:(NSSet *)otherSet will allow you to find possible recipes.
- (BOOL)intersectsSet:(NSSet *)otherSet will allow you to find recipes with at least one matching ingredient.
- (NSSet *)objectsPassingTest:(BOOL (^)(id obj, BOOL *stop))predicate can allow you to find matching ingredients count, with the proper predicate, which is something like 'is object in my array?'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With