
Mastering macOS Programming
By :

In addition to the operators provided by the Swift language, we can both override existing operators and, where necessary, create new ones.
This sounds so complicated, but it is, in fact, really easy. All we need to do is define an implementation of any given operator for any given type.
For the time being, we'll use a custom type, although what we are doing can be used equally effectively for Swift and Cocoa types.
We'll start by defining a custom type:
struct GridMovement { let rows: Int let cols: Int }
Now that we have it, we notice that it would make perfect sense to be able to apply some basic arithmetical operators to our type. We could add these to the main type declaration, but convention (young though it is) suggests we put it in an extension:
extension GridMovement { static func + (lhs: GridMovement, rhs: GridMovement) -> GridMovement { let rows = lhs.rows + rhs.rows let cols...