- When we declare protocols, the
Self
keyword signifies:- The type that implements the protocol.
- The instance of a class that conforms to the protocol.
- The instance of a struct that conforms to the protocol.
- Generics allow us to declare a class that:
- Can use a generic type only as the type for stored and type properties.
- Can use a generic type only as an argument for its initializers.
- Can work with many generic types.
- The
open class ImmutableVector3D<T: FloatingPoint>
line means:- The generic type constraint specifies that
T
must conform to the ImmutableVector3D
protocol or belong to the ImmutableVector3D
class hierarchy. - The generic type constraint specifies that
T
must conform to the FloatingPoint
protocol or belong to the FloatingPoint
class hierarchy. - The class is a subclass of
FloatingPoint
.
- The
open class Party<T: AnimalProtocol> where T: Equatable
line means:- The generic type constraint specifies that
T
must conform to both the AnimalProtocol
and Equatable
protocols. - The generic type constraint specifies that
T
must conform to either the AnimalProtocol
or Equatable
protocol. - The class is a subclass of both the
AnimalProtocol
and Equatable
classes.
- The
associatedtype
keyword followed by the desired name allows us to declare:- The generic type constraints, which is equivalent to the
where
keyword. - An associated type for a protocol.
- An alias name for the protocol name.
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.