【发布时间】:2020-04-12 07:28:11
【问题描述】:
我的应用有这样的数据。
class ShelfCollection: Object {
let shelves: List<Shelf>
}
class Shelf: Object {
let items: List<Item>
}
class Item: Object {
var name: String
let infos: List<String>
}
我正在尝试获取架子集合中的所有架子,其中任何项目都通过名称或信息列表中的元素与查询匹配。据我了解,这个谓词应该是正确的,但它崩溃了。
let wildQuery = "*" + query + "*"
shelfResults = shelfCollection.shelves.filter(
"SUBQUERY(items, $item, $item.name LIKE[c] %@ OR SUBQUERY($item.infos, $info, info LIKE[c] %@).@count > 0).@count > 0",
wildQuery, wildQuery
)
它符合 NSPredicate,但是当 Realm 尝试解析它时崩溃,抛出我
'RLMException', reason: 'Object type '(null)' not managed by the Realm'
我怀疑嵌套子查询可能是失败的原因,但我对NSPredicate 的了解还不够,无法确定。这是一个可接受的查询吗?我怎样才能使它..工作?
【问题讨论】:
标签: ios swift realm nspredicate