Test your knowledge
When we declare protocols, the
Selfkeyword 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
Tmust conform to theImmutableVector3Dprotocol or belong to theImmutableVector3Dclass hierarchy.The generic type constraint specifies that
Tmust conform to theFloatingPointprotocol or belong to theFloatingPointclass hierarchy.The class is a subclass of
FloatingPoint.
The
open class Party<T: AnimalProtocol> where T: Equatableline means:The generic type constraint specifies that
Tmust conform to both theAnimalProtocolandEquatableprotocols...