Use your custom types in operations that depend on testing for equality or order and as members of sets and dictionaries.
Basic Behaviors
Topics
Equality and Ordering
Allow your custom types to be used with simple collection operations, such as contains(_:), and standard comparison operators.
protocol EquatableA type that can be compared for value equality.
protocol ComparableA type that can be compared using the relational operators <, <=, >=, and >.
Sets and Dictionaries
Store your custom types in sets or use them as dictionary keys.
protocol HashableA type that can be hashed into a Hasher to produce an integer hash value.
struct HasherThe universal hash function used by Set and Dictionary.
String Representation
protocol CustomStringConvertible A type with a customized textual representation.
protocol LosslessStringConvertible A type that can be represented as a string in a lossless, unambiguous way.
protocol CustomDebugStringConvertible A type with a customized textual representation suitable for debugging purposes.
Raw Representation
protocol CaseIterable A type that provides a collection of all of its values.
protocol RawRepresentable A type that can be converted to and from an associated raw value.
See Also
Tools for Your Types
Serialize and deserialize instances of your types with implicit or customized encoding.
Allow values of your type to be expressed using different kinds of literals.