gpt4 book ai didi

RLMLinkingObjects 的 iOS 谓词( Realm )

转载 作者:行者123 更新时间:2023-11-29 11:49:52 25 4
gpt4 key购买 nike

我的类别中有链接对象。

@property (readonly) RLMLinkingObjects *relatedAttachments;

我只想在有相关附件的情况下进行分类。我试试这个。

NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count > 0"]];

self.categories = [[Category objectsWithPredicate:pred] sortedResultsUsingProperty:@"id" ascending:YES];

我遇到这样的错误。

RLMPrecondition(property, @"Invalid property name",

所以我试试其他的。

NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count!=nil"]];
NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"relatedAttachments.count!=NULL"]];

但是还是不行。我该怎么办?

最佳答案

您正在寻找像这样的谓词:

[NSPredicate predicateWithFormat:@"relatedAttachments.@count > 0"];

@count 是一个集合运算符,计算它出现在其右侧的集合中的元素数。

关于RLMLinkingObjects 的 iOS 谓词( Realm ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41604802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com