How to perform Realm count query

旧街凉风 提交于 2019-12-05 03:29:59

Yes, Realm still does not support .@count query. You can work around that you modify the Person model to have a count property. Then you update the count property when you append a dog object to the dogs array.

This feature request is tracked by Issue #1166 https://github.com/realm/realm-cocoa/issues/1166

Update

Realm supports @count and other collection queries from v0.96.

The syntax for the new aggregate expressions (@count, @min, @max, @sum, @avg) for Results and List looks like this:

realm.objects(Person.self).filter("dogs.@count > 0")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!