Custom operators should be avoided. Custom operators can reduce the readability of the code because there can be confusion around their functionality.
-
Overloading operators should be used sparingly, e.g. protocol conformance such as
Equatable
or 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.