使用" SELF IN"与NSPredicate和RLMResults

时间:2015-09-13 13:54:47

标签: objective-c nspredicate realm

根据https://realm.io/news/nspredicate-cheatsheet/中的文档, 我试图使用SELF来查询领域类中的一些数据但我继续获得RLMException Predicate with IN operator must compare a KeyPath with an aggregate with two values

到目前为止,我能想到的解决方案是迭代对象并获取其ID,然后使用NSPredicate条件中的ID,此处支持此解决方案{{ 3}}但我想知道是否有更有效的方式使用关键字SELF

注意:我尝试在ANYNSPredicate中使用filteredArrayUsingPredicate,但也失败了。

 (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];

}

1 个答案:

答案 0 :(得分:3)

We currently do not support SELF in that context so you are correct that you should iterate over a collection of primary keys.