Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS正在从RLMLinkingObjects执行子查询_Ios_Realm - Fatal编程技术网

iOS正在从RLMLinkingObjects执行子查询

iOS正在从RLMLinkingObjects执行子查询,ios,realm,Ios,Realm,这是我的附件模型 @interface Attachment : RLMObject @property BOOL isOfflineAvailable; @property BOOL isStarred; 在我的类别中,我设置了到附件的链接 @property (readonly) RLMLinkingObjects *relatedAttachments; + (NSDictionary *)linkingObjectsProperties { return @{

这是我的附件模型

@interface Attachment : RLMObject
@property BOOL isOfflineAvailable;
@property BOOL isStarred;
在我的类别中,我设置了到附件的链接

@property (readonly) RLMLinkingObjects *relatedAttachments;

+ (NSDictionary *)linkingObjectsProperties {
    return @{
             @"relatedAttachments": [RLMPropertyDescriptor descriptorWithClass:Attachment.class propertyName:@"category"],
             };
}
然后,我尝试查询relatedAttachments并仅在IsoflineAvailable为true时获取

NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY relatedAttachments.isOfflineAvailable == YES"];

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

问题是它是空的(尽管有数据)。我该怎么办?若它并没有链接对象,只是RLMArray,那个就可以了

RLMLinkingObjects
表示一个集合,就像数组一样,而不是单个对象。因此,尝试直接在
relatedAttachments
上调用谓词是行不通的,因为作为一个数组,它不具有
isoffineavailable
属性

相反,您可以使用
NSPredicate
子查询
语法来查询
相关附件
中符合该条件的任何对象:

RLMResults *categories = [Category objectsWhere:@"SUBQUERY(relatedAttachments, $attachment, $attachment.isOfflineAvailable == YES).@count > 0"];

谢谢你的帮助。呃……有点不对劲。如果附件IsofLineAvailable=0,我需要从relatedAttachments中筛选出附件。现在就像我得到的类别,relatedAttachments数组有2(IsoflineAvailable=0)和1(IsoflineAvailable=1)。呃,你的确切意思是什么?听起来像是
isoffineavailable==YES
需要进行更多检查,然后。。。