I am trying to make a query that gives me the total sum of percent
associated with a id_character
, here are my classes
I have a class like this:
class DBCharacter: Object
{
dynamic var id_character:String = ""
override class func primaryKey() -> String? { return "id_character" }
}
I have another class:
class DBItem: Object
{
dynamic var id_item:String = ""
dynamic var id_character:String = ""
dynamic var percent:Float = 0
}
I do it this way, but it throws me wrong:
let filterItems = NSPredicate(format: "id_character = %@", self.id_character)
let totalPercent = realm.objects(DBItem.self)
.filter(filterItems)
.sum(ofProperty: "percent")
The error it throws is:
Type of expression is ambiguous without more context