我正在尝试编写一个比较云套件数据库中两个键的谓词。到目前为止,我可以比较一个恒定值的密钥之一。当产品库存较低时,我想用它来发送通知。
我有一个名为“产品”的记录类型,该类型由一个被更新的计数组成,而一个从未改变的王量。每当计数< = 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?
发布评论
评论(1)
由于CloudKit期望右侧值是常数而不是键,因此如果您这样做的话,它将在此答案中提到您在评论中提到的错误:
但是根据这个答案这应该有效
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:
But according to this answer this should work