Swift 3 Core Data - NSExpression forFunction: “sum:” throws error (“could not cast dictionary to Day”)

前端 未结 1 645
挽巷
挽巷 2021-02-10 07:00

I have days and tasks. A day has many tasks. Every task has an attribute called \"points\" and I want to sum all points of the tasks of the current day. I used the code below (f

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-10 07:37

    This solves my problem:

    let sumRequest: NSFetchRequest = Day.fetchRequest()
    

    Instead of putting Dayas NSFetchRequestResult, I put NSFetchRequestResult itself there. Now it's working.

    I believe as I set it to a different resultType it's not [Day]anymore that gets returned, so that's why I needed to change that to be more generic or something.

    0 讨论(0)
提交回复
热议问题