Custom Operators
May 29, 2019 ยท View on GitHub
When do we use them?
Custom operators should be avoided. Custom operators can reduce the readability of the code because there can be confusion around their functionality.
Key Considerations
-
Overloading operators should be used sparingly, e.g. protocol conformance such as
Equatableor when two objects are backed by a numeric value such asPrice. -
Place the implementation of any custom operators in an extension on the type it operates on.
-
Be sure to refer to our Extensions document when deciding how to name the extension.