How to sum all numbers in attributes Core Data swift 5

Viewed 48

I find many old examples but for swift 3 and don't work on swift 5. Where I can read about this?

I think it can be done with fetchRequest.

let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Catagory")
fetchRequest.propertiesToFetch = [itemArr]
fetchRequest.resultType = .dictionaryResultType

if let results  = try? context.fetch(fetchRequest) {
    let dict = results[0] as! [String:Double]
    let totalHoursWorkedSum = dict["total"]!
    print(totalHoursWorkedSum)
} 

I only started learn Xcode and don't know how do it

0 Answers
Related