<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/basic-behaviors",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Basic Behaviors"
}
-->

# Basic Behaviors

Use your custom types in operations that depend on testing for equality or order
and as members of sets and dictionaries.

## Topics

### Equality and Ordering

Allow your custom types to be used with simple collection operations, such as `contains(_:)`,
and standard comparison operators.

[`Equatable`](/documentation/Swift/Equatable)

A type that can be compared for value equality.

[`Comparable`](/documentation/Swift/Comparable)

A type that can be compared using the relational operators `<`, `<=`, `>=`,
and `>`.

[`Identifiable`](/documentation/Swift/Identifiable)

A class of types whose instances hold the value of an entity with stable
identity.

### Copying

[`Copyable`](/documentation/Swift/Copyable)

A type whose values can be implicitly or explicitly copied.

[`BitwiseCopyable`](/documentation/Swift/BitwiseCopyable)

[`Escapable`](/documentation/Swift/Escapable)

A type whose values can persist beyond their immediate local scope.

### Borrowing

[`Ref`](/documentation/Swift/Ref)

A safe reference allowing in-place reads to a shared value.

[`MutableRef`](/documentation/Swift/MutableRef)

A safe mutable reference allowing in-place mutation to an exclusive value.

### Sets and Dictionaries

Store your custom types in sets or use them as dictionary keys.

[`Hashable`](/documentation/Swift/Hashable)

A type that can be hashed into a `Hasher` to produce an integer hash value.

[`Hasher`](/documentation/Swift/Hasher)

The universal hash function used by `Set` and `Dictionary`.

### String Representation

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

A type with a customized textual representation.

[`LosslessStringConvertible`](/documentation/Swift/LosslessStringConvertible)

A type that can be represented as a string in a lossless, unambiguous way.

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

A type with a customized textual representation suitable for debugging
purposes.

### Raw Representation

[`CaseIterable`](/documentation/Swift/CaseIterable)

A type that provides a collection of all of its values.

[`RawRepresentable`](/documentation/Swift/RawRepresentable)

A type that can be converted to and from an associated raw value.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)