将 NSSet 中的对象与 NSArray 中的对象进行比较

发布于 2024-09-30 03:29:41 字数 333 浏览 3 评论 0原文

我已经思考这个问题有一段时间了,但我还无法得到一个简洁有效的解决方案。

问题:

我有一个食谱列表,它是一个 NSArray,每个食谱对象都包含成分作为 NSSet 对象。数据是一对多的关系&来自 coredata。 现在有另一个 NSArray 列表,其中包含特定人当前拥有的物品(成分)。

现在我必须以某种方式将用户当前拥有的物品与食谱和食谱中的成分进行比较。在表格视图中推荐用户食谱,其中包含所有项目、缺少 1 个项目、缺少两个项目和缺少三个项目等部分。

你们认为我应该如何解决这个问题。 我尝试过一些事情,但每次我都会更加迷失。

任何帮助/指示将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2024-10-07 03:29:41

NSSet 中有一些有趣的方法:

  • + (id)setWithArray:(NSArray *)array 将允许您快速将数组转换为集合。

  • - (BOOL)isSubsetOfSet:(NSSet *)otherSet 将允许您找到可能的食谱。

  • - (BOOL)intersectsSet:(NSSet *)otherSet 将允许您查找至少包含一种匹配成分的食谱。

  • - (NSSet *)objectsPassingTest:(BOOL (^)(id obj, BOOL *stop))predicate 可以让您使用适当的谓词找到匹配的成分计数,类似于'is object in my array?'

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?'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文