Reputation: 22374
I have tried to use the @count
function to get data according to that but it somehow crashed without crash report.
Here is the code
class PSMedia: Object {
@objc dynamic var id = ""
@objc dynamic var promotional_status = false
var promotions = List<String>()
}
And here is that query that caused an issue
realm.objects(PSMedia.self).filter("promotions.@count <= 5")
What's wrong here? I have followed realm swift doc and used the @count
function same as described in that doc.
Upvotes: 1
Views: 551
Reputation: 35648
I am pretty sure @count does not work on Lists of primitives. Realm didn't used to support lists of primitives at all, it now does but there is some missing functionality.
EDIT: Release 10.7 added support for filters/queries as well as aggregate functions on primitives so the below info is no longer completely valid. However, it's still something to be aware of.
Change your promotions to be a list of other realm objects
class PromotionClass: Object {
@objc dynamic var promotion = ""
}
and then
class PSMedia: Object {
@objc dynamic var id = ""
@objc dynamic var promotional_status = false
let promotions = List<PromotionClass>()
}
then this will work
realm.objects(PSMedia.self).filter("promotions.@count <= 5")
EDIT
Yep, that's correct. It's not supported. Here's the Github link for that issue
Swift docs should make it clear that filtering by someListOfPrimitives.@count
isn't supported #6079
Upvotes: 1