【发布时间】:2018-05-10 23:27:58
【问题描述】:
一段时间以来,我一直在尝试编写一个查询来访问一个等于特定键的对象,但没有成功。我已经浏览了 SO 和 Realm 文档,但没有任何运气。
如果我打印出 CachedCodes RLMObject 的结构,它看起来像这样:
CachedCodes {
Codes = Codes {
assets = RLMArray<KVString> (
[0] KVString {
key = Some Key;// this is what I'd want to query for
value = Some Value;
}
);
};
}
这是我的班级结构:
@interface CachedCodes : RLMObject
@property (nonatomic, strong, readonly) Codes *Codes;//readwrite in .m
@end
@interface Codes : RLMObject
@property (nonatomic, strong, readonly) RLMArray<KVString *><KVString> *assets;//readwrite in .m
@end
@interface KVString : RLMObject
@property (nonatomic, strong, readonly) NSString *key;//readwrite in .m
@property (nonatomic, strong, readonly) NSString *value;//readwrite in .m
@end
RLM_ARRAY_TYPE(KVString);
这是我尝试过的:
[CachedObjects objectsWhere:@"Codes.assets.key == 'Some key'"];
错误:包含数组属性的键路径必须使用聚合操作。
[CachedObjects objectsWhere:@"Codes.assets.key IN 'Some key'"];
错误:包含数组属性的键路径必须使用聚合操作。
[CachedObjects objectsWhere:@"ANY Codes.assets.key == 'Some key'"];
错误:没有错误。它不会崩溃,也不会给我带有键“Some key”的对象。相反,它给了我所有的对象。
如果有人有任何意见,我将永远感激:)
【问题讨论】:
-
明确地说,您希望查询返回一个
KVString对象,其key的值与您想要的字符串匹配? -
是的,没错。
标签: objective-c realm