将 "SELF IN" 与 NSPredicate 和 RLMResults 一起使用
Using "SELF IN" with NSPredicate and RLMResults
根据 https://realm.io/news/nspredicate-cheatsheet/ 中的文档,
我正在尝试使用 SELF 查询领域 class 中的一些数据,但我一直收到 RLMException Predicate with IN operator must compare a KeyPath with an aggregate with two values
到目前为止我能想到的解决方案是遍历对象并获取它们的 ID,然后在 NSPredicate
条件下使用 ID,这里支持此解决方案 NSPredicate using RLMResults as an argument 但我是想知道使用关键字 SELF
是否有更有效的方法。
注意:我尝试在 NSPredicate
和 filteredArrayUsingPredicate
中使用 ANY
,但也失败了。
(void)deleteOldOfferObjects : (RLMResults *) newOfferObjects{
NSPredicate *oldObjects = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", newOfferObjects];
RLMResults *oldObjectsArr =[Offer objectsWithPredicate:oldObjects];
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[realm deleteObjects:oldObjectsArr];
[realm commitWriteTransaction];
}
我们目前在该上下文中不支持 SELF
,因此您应该迭代主键集合是正确的。
根据 https://realm.io/news/nspredicate-cheatsheet/ 中的文档,
我正在尝试使用 SELF 查询领域 class 中的一些数据,但我一直收到 RLMException Predicate with IN operator must compare a KeyPath with an aggregate with two values
到目前为止我能想到的解决方案是遍历对象并获取它们的 ID,然后在 NSPredicate
条件下使用 ID,这里支持此解决方案 NSPredicate using RLMResults as an argument 但我是想知道使用关键字 SELF
是否有更有效的方法。
注意:我尝试在 NSPredicate
和 filteredArrayUsingPredicate
中使用 ANY
,但也失败了。
(void)deleteOldOfferObjects : (RLMResults *) newOfferObjects{
NSPredicate *oldObjects = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", newOfferObjects];
RLMResults *oldObjectsArr =[Offer objectsWithPredicate:oldObjects];
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[realm deleteObjects:oldObjectsArr];
[realm commitWriteTransaction];
}
我们目前在该上下文中不支持 SELF
,因此您应该迭代主键集合是正确的。