Who can help with this piece of code

It is try to do local reasoning in action.
Why I have this error in line 37
self.state = s // Expression type '()' is ambiguous without more context

The playground has a more useful diagnostic:

Cannot assign value of type 'State<Cell.Swarm, Cell.Puck>' to type 'State<Model.Cell.Swarm, Model.Cell.Puck>'

This is because Model.Cell.Swarm are not necessarily the same as Cell.Swarm despite similar name. The function can use any Cell other than Model.Cell. Say, if Model.Cell is Cell1, the caller can still supply Cell2, which is a different type. Same with Puck.

What you'd need is to enforce the that the cell is the same type as the Model.Cell:

mutating func handle(cell: Model.Cell?) { ... }

because you can't really handle any Cell that conforms to CornerRulesCell, only this particular Model.Cell.

Terms of Service

Privacy Policy

Cookie Policy