Post

Replies

Boosts

Views

Activity

CoreData - Sum/Count a FetchRequest
Hi everyone, I am trying to sum and count each element of a fetch request which is looking for the best 10 tournaments in data. var tournamentRequest : FetchRequest<Tournament> var tournamentTop10 : FetchedResults<Tournament {tournamentRequest.wrappedValue}     init(predicate:String){     self.predicate = predicate     self.tournamentRequest = FetchRequest (entity: Tournament.entity(),                   sortDescriptors: [NSSortDescriptor(keyPath: \Tournament.point, ascending: false)],                   predicate: NSPredicate(format: "date >= %@", makeDate(year: calendar.component(.year, from: date)-1, month: calendar.component(.month, from: date), day: 01, hr: 0, min: 0, sec: 0) as CVarArg)) The Tournament structure has "point" member. I would like to SUM all point of all tournament and COUNT the number of tournaments. Can you help me? Am I clear enough? Thank you :)
1
0
1.4k
Oct ’21