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 Equatable
A type that can be compared for value equality.
protocol Comparable
A 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 Hashable
A type that can be hashed into a Hasher
to produce an integer hash value.
struct Hasher
The universal hash function used by Set
and Dictionary
.
String Representation
protocol Custom String Convertible
A type with a customized textual representation.
protocol Lossless String Convertible
A type that can be represented as a string in a lossless, unambiguous way.
protocol Custom Debug String Convertible
A type with a customized textual representation suitable for debugging purposes.
Raw Representation
protocol Case Iterable
A type that provides a collection of all of its values.
protocol Raw Representable
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.