- Mastering macOS Programming
- Stuart Grimshaw
- 73字
- 2021-07-02 22:54:38
Equivalence
We can also implement the == operator, since again it makes sense to be able to compare two GridMovement objects:
extension GridMovement
{
static prefix func -><- (movement: inout GridMovement)
-> GridMovement
{
return GridMovement (rows: movement.col, cols: movement.row)
}
}
These GridMovement objects are usable now as, say, chessboard moves that can be added together, multiplied by an integral number of moves, and compared with each other. Now go write a chess program.
Just kidding.