do {
let result = try Realm().objects(Pros.self)
print(result)
let filterResult = result.filter({ $0.category.filter({$0.type_cat == ""})})
print(filterResult)
}
catch {
print(error)
}
它给我的错误是"模糊地提及会员' =='" 所以我想要添加
答案 0 :(得分:1)
我找到了解决方案,它的工作非常适合我
do {
let result = try Realm().objects(Pros.self)
print(result)
let predicate = NSPredicate(format: "SELF.type == %@ AND SELF.status == 'valide' AND ANY category.type_sector = %@ AND SELF.status == 'valide'", arrType[(selectedFromType?.row)!], arrTypeSector[(selectedFromSector?.row)!])
let arrFiltered = result.filter(predicate)
print(arrFiltered)
}
catch
{
print(error)
}
答案 1 :(得分:0)
根据Realm docs过滤章节,尝试更改您的请求:
let type = ""
let result = try Realm().objects(Pros.self).filter("category.type_cat == %@",type)
答案 2 :(得分:0)
Realm().objects(Pros.self)
将返回Result<Pros>
哪种领域数据。你的filter
函数语法是Swift的函数,不是Realm的函数。在使用Result<Pros>
之前,您应该将[Pros]
转换为filter
:
let result = Array(try Realm().objects(Pros.self))
let filterResult = result.filter({ $0.category.filter({$0.type_cat == ""})})
或者您可以在Realm中使用filter
函数构建。请查看realm.io docs。