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

前端 未结 1 1539
名媛妹妹
名媛妹妹 2021-02-10 06:59

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:33

    This solves my problem:

    let sumRequest: NSFetchRequest<NSFetchRequestResult> = 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)
提交回复
热议问题