将两个关键值与Nspredicate CloudKit进行比较

发布于 2025-02-10 01:42:00 字数 356 浏览 1 评论 0 原文

我正在尝试编写一个比较云套件数据库中两个键的谓词。到目前为止,我可以比较一个恒定值的密钥之一。当产品库存较低时,我想用它来发送通知。

我有一个名为“产品”的记录类型,该类型由一个被更新的计数组成,而一个从未改变的王量。每当计数< = mincount时,我都会使用它显示“库存低”标签。

这是我正在使用的谓词的一个示例,该谓词具有通知的恒定值:

let predicate = NSPredicate(format: "count <= %i", 10)

对于一种特定产品,我知道Mincount为10,因此对于该产品而言,这是正确的,但是其他产品具有不同的Mincount值。有办法这样做吗?

I am trying to write a predicate that compares two keys in a cloud kit database. So far I can compare one of the keys with a constant value. I want to use this to send a notification when the inventory of a product is low.

I have a record type called products which consists of a count that gets updated, and a minCount that never changes. I use this to display an "Inventory Low" label whenever count <= minCount.

Here is an example of the predicate I'm using with the constant value for the notifications:

let predicate = NSPredicate(format: "count <= %i", 10)

For one specific product I know that the minCount is 10, so this works properly for that one product, but the other products have different minCount values. Is there a way to do this?

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

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

发布评论

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

评论(1

一萌ing 2025-02-17 01:42:00

由于CloudKit期望右侧值是常数而不是键,因此如果您这样做的话,它将在此答案中提到您在评论中提到的错误:

let predicate = NSPredicate(format: "count <= minCount")

但是根据这个答案这应该有效

let predicate = NSPredicate(format: "%K <= %i", "count", "minCount")

Since the CloudKit will expect the right hand side value to be a constant rather than a key, it will throw you the error you are mentioning in the comment to this answer if you to this:

let predicate = NSPredicate(format: "count <= minCount")

But according to this answer this should work

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