-
Book Overview & Buying
-
Table Of Contents
Swift 3 Object-Oriented Programming - Second Edition
By :
Add the following operators to work with both MutableVector3D<T> and ImmutableVector3D<T>:
==: This determines whether all the elements that compose a 3D vector (x, y, and z) are equal.
+: This sums each element that composes a 3D vector and saves the result in each element or in the new returned instance according to the class version (mutable or immutable). The new x must have the result of the left-hand side x + right-hand side x, the new y must be that of the left-hand side y + right-hand side y, and the new z must be that of the left-hand side z + right-hand side z.
In Chapter 4, Inheritance, Abstraction and Specialization, we created an Animal class and then defined specific operator functions to allow us to use operators with instances of this class. Redefine this class to conform to both the Comparable and Equatable protocols.
The following lines show the source code for the Equatable protocol:
public protocol Equatable {
static func ==(lhs: Self...