SwiftUI, CoreData and To Many relationship

Viewed 24

I am developing a SwiftUI application using CoreData. At some point, I have to handle a CoreData Exam entity that have a To Many relationship (called answerSheets) with an entity named AnswerSheet.

I was expecting to loop over this To Many relationship with

ForEach(self.exam.answerSheets) { answerSheet in

   ...
}

in order to display a list of the answer sheets. But, when compiling, I get a

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

error for the View object. In order to compile, I have to replace self.exam.answerSheets with self.exam.answerSheets?.allObjects as! [AnswerSheet] which works but seem to break completely the type system checker.

I also have many problems to sort this list in order to display it according to the lexical ordering of a string in AnswerSheet.

Thanks for your help, François

0 Answers
Related