Swift 如何在域中执行查询以检查相关对象的属性?

Swift 如何在域中执行查询以检查相关对象的属性?,swift,realm,Swift,Realm,但是聚合函数不能与其他聚合函数组合,似乎不能在同一个查询中使用@count和@min。目前,没有简单的方法来查询想要得到的结果 简单的解决方案是添加count属性以正确回答问题对象 realm.objects(Question).filter("answers.@count == @min AND answers.correct == true") realm.objects(Question).filter("answers.@count == @min AND answers.correc

但是聚合函数不能与其他聚合函数组合,似乎不能在同一个查询中使用
@count
@min

目前,没有简单的方法来查询想要得到的结果

简单的解决方案是添加
count
属性以正确回答
问题
对象

realm.objects(Question).filter("answers.@count == @min AND answers.correct == true")
realm.objects(Question).filter("answers.@count == @min AND answers.correct == true")
class Question: Object {
    let answers = List<Answer>()
    dynamic var correctAnswerCount = 0
}
let fewest = realm
    .objects(Question)
    .sorted("correctAnswerCount", ascending: true).first