Swift is the standard library that underpins all Swift code, providing the core types, collections, protocols, generics, and language primitives the language is built on. You model data and behavior against fundamental protocols such as Equatable, Comparable, Collection, BidirectionalCollection, and AdditiveArithmetic, and adopt protocols like Codable's Encodable and Decodable, CaseIterable, and CustomStringConvertible to give your own types standard capabilities. The library also defines numeric and literal protocols including BinaryInteger, BinaryFloatingPoint, ExpressibleByIntegerLiteral, and ExpressibleByArrayLiteral, along with supporting types like AnyKeyPath, CollectionDifference, and the DecodingError and EncodingError errors. It is available across iOS, macOS, tvOS, watchOS, and visionOS.
Equality, Ordering, and Hashing 5
Fundamental protocols that give types value equality, ordering, and hash-based behavior.
- PrEquatableA type that can be compared for value equality.
- PrComparableA type that can be compared using the relational operators `<`, `<=`, `>=`,
- PrHashableA type that can be hashed into a `Hasher` to produce an integer hash value.
- PrIdentifiableiOS 13.0+A class of types whose instances hold the value of an entity with stable
- PrStrideableA type representing continuous, one-dimensional values that can be offset
Sequences and Collections 18
Protocols and supporting types for iterating, indexing, slicing, and mutating ordered values.
- PrSequenceA type that provides sequential, iterated access to its elements.
- PrIteratorProtocolA type that supplies the values of a sequence one at a time.
- PrCollectionA sequence whose elements can be traversed multiple times,
- PrBidirectionalCollectionA collection that supports backward as well as forward traversal.
- PrRandomAccessCollectionA collection that supports efficient random-access index traversal.
- PrMutableCollectionA collection that supports subscript assignment.
- PrRangeReplaceableCollectionA collection that supports replacement of an arbitrary subrange of elements
- PrLazySequenceProtocolA sequence on which normally-eager sequence operations are implemented
- PrLazyCollectionProtocolA collection that lazily evaluates the transformations applied to it.
- PrBorrowingSequenceA type that provides sequential, borrowing access to its elements.
- PrBorrowingIteratorProtocolA type that provides borrowed access to the values of a borrowing sequence.
- PrSetAlgebraA type that provides mathematical set operations.
- PrOptionSetA type that presents a mathematical set interface to a bit set.
- StCollectionDifferenceiOS 13.0+A collection of insertions and removals that describe the difference
- StDiscontiguousSliceiOS 18.0+A collection wrapper that provides access to the elements of a collection,
- StRangeSetiOS 18.0+A set of values of any comparable type, represented by ranges.
- PrRangeExpressionA type that can be used to slice a collection.
- StSpanIteratorAn iterator that yields the elements of a span of contiguous storage.
Numbers and Arithmetic 14
Protocols that model integer, floating-point, and SIMD numeric types and their arithmetic.
- PrAdditiveArithmeticA type with values that support addition and subtraction.
- PrNumericA type with values that support multiplication.
- PrSignedNumericA numeric type with a negation operation.
- PrBinaryIntegerAn integer type with a binary representation.
- PrFixedWidthIntegerAn integer type that uses a fixed size for every instance.
- PrSignedIntegerAn integer type that can represent both positive and negative values.
- PrUnsignedIntegerAn integer type that can represent only nonnegative values.
- PrFloatingPointA floating-point numeric type.
- PrBinaryFloatingPointA radix-2 (binary) floating-point type.
- EnFloatingPointRoundingRuleA rule for rounding a floating-point number.
- PrSIMDA SIMD vector of a fixed number of elements.
- PrSIMDScalarA type that can be used as an element in a SIMD vector.
- PrSIMDStorageA type that can function as storage for a SIMD vector type.
- PrRandomNumberGeneratorA type that provides uniformly distributed random data.
Literal Expressibility 11
Protocols that let a type be initialized directly from a Swift literal.
- PrExpressibleByIntegerLiteralA type that can be initialized with an integer literal.
- PrExpressibleByFloatLiteralA type that can be initialized with a floating-point literal.
- PrExpressibleByBooleanLiteralA type that can be initialized with the Boolean literals `true` and
- PrExpressibleByNilLiteralA type that can be initialized using the nil literal, `nil`.
- PrExpressibleByStringLiteralA type that can be initialized with a string literal.
- PrExpressibleByStringInterpolationA type that can be initialized by string interpolation with a string
- PrExpressibleByExtendedGraphemeClusterLiteralA type that can be initialized with a string literal containing a single
- PrExpressibleByUnicodeScalarLiteralA type that can be initialized with a string literal containing a single
- PrExpressibleByArrayLiteralA type that can be initialized using an array literal.
- PrExpressibleByDictionaryLiteralA type that can be initialized using a dictionary literal.
- PrStringInterpolationProtocolRepresents the contents of a string literal with interpolations while it's
Strings and Text 5
Protocols for working with string values, Unicode, and text output streams.
- PrStringProtocolA type that can represent a string as a collection of characters.
- PrUnicodeCodecA Unicode encoding form that translates between Unicode scalar values and
- PrTextOutputStreamA type that can be the target of text-streaming operations.
- PrTextOutputStreamableA source of text-streaming operations.
- PrCVarArgA type whose instances can be encoded, and appropriately passed, as
Encoding and Decoding 17
The Codable protocols, containers, and errors for serializing and deserializing values.
- PrEncodableA type that can encode itself to an external representation.
- PrDecodableA type that can decode itself from an external representation.
- PrEncoderA type that can encode values into a native format for external
- PrDecoderA type that can decode values from a native format into in-memory
- PrCodingKeyA type that can be used as a key for encoding and decoding.
- PrCodingKeyRepresentableiOS 15.4+A type that can be converted to and from a coding key.
- StCodingUserInfoKeyA user-defined key for providing context during encoding and decoding.
- PrKeyedEncodingContainerProtocolA type that provides a view into an encoder's storage and is used to hold
- PrKeyedDecodingContainerProtocolA type that provides a view into a decoder's storage and is used to hold
- StKeyedEncodingContainerA concrete container that provides a view into an encoder's storage, making
- StKeyedDecodingContainerA concrete container that provides a view into a decoder's storage, making
- PrUnkeyedEncodingContainerA type that provides a view into an encoder's storage and is used to hold
- PrUnkeyedDecodingContainerA type that provides a view into a decoder's storage and is used to hold
- PrSingleValueEncodingContainerA container that can support the storage and direct encoding of a single
- PrSingleValueDecodingContainerA container that can support the storage and direct decoding of a single
- EnEncodingErrorAn error that occurs during the encoding of a value.
- EnDecodingErrorAn error that occurs during the decoding of a value.
Description and Reflection 8
Protocols and types that produce textual representations and reflect over a value's structure.
- PrCustomStringConvertibleA type with a customized textual representation.
- PrCustomDebugStringConvertibleA type with a customized textual representation suitable for debugging
- PrLosslessStringConvertibleA type that can be represented as a string in a lossless, unambiguous way.
- PrCustomPlaygroundDisplayConvertibleA type that supplies a custom description for playground logging.
- PrCustomReflectableA type that explicitly supplies its own mirror.
- PrCustomLeafReflectableA type that explicitly supplies its own mirror, but whose
- StMirrorA representation of the substructure and display style of an instance of
- PrMirrorPathA protocol for legitimate arguments to `Mirror`'s `descendant`
Key Paths 6
Reference types that capture a path to a property for reading and writing values.
- ClAnyKeyPathA type-erased key path, from any root type to any resulting value
- ClPartialKeyPathA partially type-erased key path, from a concrete root type to any
- ClKeyPathA key path from a specific root type to a specific resulting value type.
- ClWritableKeyPathA key path that supports reading from and writing to the resulting value.
- ClReferenceWritableKeyPathA key path that supports reading from and writing to the resulting value
- Pr_AppendKeyPathAn implementation detail of key path expressions; do not use this protocol
Concurrency and Actors 10
Protocols and types that support actors, executors, task-local values, and continuations.
- PrActoriOS 13.0+Common protocol to which all actors conform.
- PrGlobalActoriOS 13.0+A type that represents a globally-unique actor that can be used to isolate
- PrExecutoriOS 13.0+A service that can execute jobs.
- PrSerialExecutoriOS 13.0+A service that executes jobs.
- PrTaskExecutoriOS 18.0+An executor that may be used as preferred executor by a task.
- ClTaskLocaliOS 13.0+Wrapper type that defines a task-local value key.
- StTaskPriorityiOS 13.0+The priority of a task.
- StUnsafeCurrentTaskiOS 13.0+An unsafe reference to the current task.
- StCheckedContinuationiOS 13.0+A mechanism to interface
- StCancellationErroriOS 13.0+An error that indicates a task was canceled.
Asynchronous Sequences 18
Protocols and adapter types for producing and transforming values asynchronously over time.
- PrAsyncSequenceiOS 13.0+A type that provides asynchronous, sequential, iterated access to its
- PrAsyncIteratorProtocoliOS 13.0+A type that asynchronously supplies the values of a sequence one at a
- StAsyncStreamiOS 13.0+An asynchronous sequence generated from a closure that calls a continuation
- StAsyncThrowingStreamiOS 13.0+An asynchronous sequence generated from an error-throwing closure that
- StAsyncMapSequenceiOS 13.0+An asynchronous sequence that maps the given closure over the asynchronous
- StAsyncCompactMapSequenceiOS 13.0+An asynchronous sequence that maps a given closure over the asynchronous
- StAsyncFilterSequenceiOS 13.0+An asynchronous sequence that contains, in order, the elements of
- StAsyncFlatMapSequenceiOS 13.0+An asynchronous sequence that concatenates the results of calling a given
- StAsyncDropFirstSequenceiOS 13.0+An asynchronous sequence which omits a specified number of elements from the
- StAsyncDropWhileSequenceiOS 13.0+An asynchronous sequence which omits elements from the base sequence until a
- StAsyncPrefixSequenceiOS 13.0+An asynchronous sequence, up to a specified maximum length,
- StAsyncPrefixWhileSequenceiOS 13.0+An asynchronous sequence, containing the initial, consecutive
- StAsyncThrowingMapSequenceiOS 13.0+An asynchronous sequence that maps the given error-throwing closure over the
- StAsyncThrowingCompactMapSequenceiOS 13.0+An asynchronous sequence that maps an error-throwing closure over the base
- StAsyncThrowingFilterSequenceiOS 13.0+An asynchronous sequence that contains, in order, the elements of
- StAsyncThrowingFlatMapSequenceiOS 13.0+An asynchronous sequence that concatenates the results of calling a given
- StAsyncThrowingDropWhileSequenceiOS 13.0+An asynchronous sequence which omits elements from the base sequence until a
- StAsyncThrowingPrefixWhileSequenceiOS 13.0+An asynchronous sequence, containing the initial, consecutive
Time and Clocks 5
Protocols and clocks that measure instants, durations, and intervals for scheduling work.
- PrClockiOS 16.0+A mechanism in which to measure time, and delay work until a given point
- PrInstantProtocoliOS 16.0+A type that represents a specific point in time for a clock.
- PrDurationProtocoliOS 16.0+A type that defines a duration for a given `InstantProtocol` type.
- StContinuousClockiOS 16.0+A clock that measures time that always increments and does not stop
- StSuspendingClockiOS 16.0+A clock that measures time that always increments but stops incrementing
Regular Expressions 7
Types and protocols for building, matching, and configuring regular expressions.
- StRegexiOS 16.0+A regular expression.
- PrRegexComponentiOS 16.0+A type that represents a regular expression.
- PrCustomConsumingRegexComponentiOS 16.0+A regex component that defines its own custom matching behavior.
- StAnyRegexOutputiOS 16.0+The type-erased, dynamic output of a regular expression match.
- StRegexSemanticLeveliOS 16.0+A semantic level to use during regex matching.
- StRegexRepetitionBehavioriOS 16.0+Specifies how much to attempt to match when using a quantifier.
- StRegexWordBoundaryKindiOS 16.0+A word boundary algorithm to use during regex matching.
Type Capabilities and Conventions 9
Marker and convention protocols that confer raw values, ownership, sendability, and enumeration.
- PrRawRepresentableA type that can be converted to and from an associated raw value.
- PrCaseIterableA type that provides a collection of all of its values.
- PrErrorA type representing an error value that can be thrown.
- PrSendableA thread-safe type whose values can be shared across arbitrary isolation
- PrSendableMetatypeA type whose metatype can be shared across arbitrary isolation domains
- PrUnsafeSendableA type whose values can safely be passed across concurrency domains by copying,
- PrCopyableA type whose values can be implicitly or explicitly copied.
- PrEscapableA type whose values can persist beyond their immediate local scope.
- PrBitwiseCopyableA protocol marking types that can be safely copied bit by bit.
Low-Level Storage 1
A class for managing manually allocated buffer storage backing collection types.
- ClManagedBufferA class whose instances contain a property of type `Header` and raw
Structures 111
- StAnyBidirectionalCollectionA type-erased wrapper over any collection with indices that
- StAnyCollectionA type-erased wrapper over any collection with indices that
- StAnyHashableA type-erased hashable value.
- StAnyIndexA wrapper over an underlying index that hides the specific underlying type.
- StAnyIteratorA type-erased iterator of `Element`.
- StAnyRandomAccessCollectionA type-erased wrapper over any collection with indices that
- StAnySequenceA type-erased sequence.
- StArrayAn ordered, random-access collection.
- StArraySliceA slice of an `Array`, `ContiguousArray`, or `ArraySlice` instance.
- StAutoreleasingUnsafeMutablePointerA mutable pointer addressing an Objective-C reference that doesn't own its
- StBoolA value type whose instances are either `true` or `false`.
- StBorrowingIteratorAdapter
- StCVaListPointer
- StCharacterA single extended grapheme cluster that approximates a user-perceived
- StClosedRangeAn interval from a lower bound up to, and including, an upper bound.
- StCollectionOfOneA collection containing a single element.
Show 95 more
- StContiguousArrayA contiguously stored array.
- StDefaultIndicesA collection of indices for an arbitrary collection
- StDefaultStringInterpolationRepresents a string literal with interpolations while it's being built up.
- StDictionaryA collection whose elements are key-value pairs.
- StDoubleA double-precision (64-bit), floating-point value type.
- StDropFirstSequenceA sequence that lazily consumes and drops `n` elements from an underlying
- StDropWhileSequenceA sequence that lazily consumes and drops `n` elements from an underlying
- StDurationiOS 16.0+A representation of high precision time.
- StEmptyCollectionA collection whose element type is `Element` but that is always empty.
- StEnumeratedSequenceAn enumeration of the elements of a sequence or collection.
- StFlattenSequenceA sequence consisting of all the elements contained in each segment
- StFloatA single-precision (32-bit), floating-point value type.
- StFloat16iOS 14.0+A half-precision (16-bit), floating-point value type.
- StHasherThe universal hash function used by `Set` and `Dictionary`.
- StIndexingIteratorA type that iterates over a collection using its indices.
- StInlineArrayA fixed-size array.
- StIntA signed integer value type.
- StInt128iOS 18.0+A 128-bit signed integer value type.
- StInt16A 16-bit signed integer value
- StInt32A 32-bit signed integer value
- StInt64A 64-bit signed integer value
- StInt8An 8-bit signed integer value
- StIteratorSequenceA sequence built around an iterator of type `Base`.
- StJoinedSequenceA sequence that presents the elements of a base sequence of sequences
- StKeyValuePairsA lightweight collection of key-value pairs.
- StLazyDropWhileSequenceA sequence whose elements consist of the elements that follow the initial
- StLazyFilterSequenceA sequence whose elements consist of the elements of some base
- StLazyMapSequenceA `Sequence` whose elements consist of those in a `Base`
- StLazyPrefixWhileSequenceA sequence whose elements consist of the initial consecutive elements of
- StLazySequenceA sequence containing the same elements as a `Base` sequence, but
- StManagedBufferPointerContains a buffer object, and provides access to an instance of
- StMutableRawSpaniOS 12.2+
- StMutableSpaniOS 12.2+
- StObjectIdentifierA unique identifier for a class instance, actor instance, or metatype.
- StOpaquePointerA wrapper around an opaque C pointer.
- StOutputRawSpaniOS 12.2+
- StOutputSpaniOS 12.2+
- StPartialRangeFromA partial interval extending upward from a lower bound.
- StPartialRangeThroughA partial interval up to, and including, an upper bound.
- StPartialRangeUpToA partial half-open interval up to, but not including, an upper bound.
- StPrefixSequenceA sequence that only consumes up to `n` elements from an underlying
- StRangeA half-open interval from a lower bound up to, but not including, an upper
- StRawSpaniOS 12.2+`RawSpan` represents a contiguous region of memory
- StRepeatedA collection whose elements are all identical.
- StReversedCollectionA collection that presents the elements of its base collection
- StSIMD16A vector of 16 scalar values.
- StSIMD2A vector of two scalar values.
- StSIMD3A vector of three scalar values.
- StSIMD32A vector of 32 scalar values.
- StSIMD4A vector of four scalar values.
- StSIMD64A vector of 64 scalar values.
- StSIMD8A vector of eight scalar values.
- StSIMDMask
- StSetAn unordered collection of unique elements.
- StSliceA view into a subsequence of elements of another collection.
- StSpaniOS 12.2+`Span<Element>` represents a contiguous region of memory
- StStaticBigIntiOS 16.4+An immutable arbitrary-precision signed integer.
- StStaticStringA string type designed to represent text that is known at compile time.
- StStrideThroughA sequence of values formed by striding over a closed interval.
- StStrideThroughIteratorAn iterator for a `StrideThrough` instance.
- StStrideToA sequence of values formed by striding over a half-open interval.
- StStrideToIteratorAn iterator for a `StrideTo` instance.
- StStringA Unicode string value that is a collection of characters.
- StSubstringA slice of a string.
- StSystemRandomNumberGeneratorThe system's default source of random data.
- StUIntAn unsigned integer value type.
- StUInt128iOS 18.0+A 128-bit unsigned integer value type.
- StUInt16A 16-bit unsigned integer value
- StUInt32A 32-bit unsigned integer value
- StUInt64A 64-bit unsigned integer value
- StUInt8An 8-bit unsigned integer value
- StUTF8SpanA borrowed view into contiguous memory that contains validly-encoded UTF-8
- StUnfoldSequenceA sequence whose elements are produced via repeated applications of a
- StUnmanagedA type for propagating an unmanaged object reference.
- StUnsafeBufferPointerA nonowning collection interface to a buffer of
- StUnsafeMutableBufferPointerA nonowning collection interface to a buffer of mutable
- StUnsafeMutablePointerA pointer for accessing and manipulating data of a
- StUnsafeMutableRawBufferPointerA mutable nonowning collection interface to the bytes in a
- StUnsafeMutableRawPointerA raw pointer for accessing and manipulating untyped data.
- StUnsafePointerA pointer for accessing data of a specific type.
- StUnsafeRawBufferPointerA nonowning collection interface to the bytes in a
- StUnsafeRawPointerA raw pointer for accessing untyped data.
- StZip2SequenceA sequence of pairs built out of two underlying sequences.
- StDiscardingTaskGroupiOS 17.0+A discarding group that contains dynamically created child tasks.
- StExecutorJobiOS 17.0+A unit of schedulable work.
- StJobDeprecated equivalent of ``ExecutorJob``.
- StJobPriorityiOS 17.0+The priority of this job.
- StTaskiOS 13.0+A unit of asynchronous work.
- StTaskGroupiOS 13.0+A group that contains dynamically created child tasks.
- StThrowingDiscardingTaskGroupiOS 17.0+A throwing discarding group that contains dynamically created child tasks.
- StThrowingTaskGroupiOS 13.0+A group that contains throwing, dynamically created child tasks.
- StUnownedJobiOS 13.0+A unit of schedulable work.
- StUnownedSerialExecutoriOS 13.0+An unowned reference to a serial executor (a `SerialExecutor`
- StUnownedTaskExecutoriOS 18.0+
- StUnsafeContinuationiOS 13.0+A mechanism to interface
Enumerations 10
- EnCommandLineCommand-line arguments for the current process.
- EnFloatingPointClassificationThe IEEE 754 floating-point classes.
- EnFloatingPointSignThe sign of a floating-point value.
- EnMemoryLayoutThe memory layout of a type, describing its size, stride, and alignment.
- EnNeverA type that has no values and can't be constructed.
- EnOptionalA type that represents either a wrapped value or the absence of a value.
- EnResultA value that represents either a success or a failure, including an
- EnUnboundedRange_A range expression that represents the entire range of a collection.
- EnUnicodeA namespace for Unicode utilities.
- EnUnicodeDecodingResultThe result of one Unicode decoding step.
Actors 1
- AcMainActoriOS 13.0+A singleton actor whose executor is equivalent to the main
Type Aliases 59
- TyAnyClassThe protocol to which all class types implicitly conform.
- TyAnyObjectThe protocol to which all classes implicitly conform.
- TyBooleanLiteralTypeThe default type for an otherwise-unconstrained Boolean literal.
- TyCBoolThe C '_Bool' and C++ 'bool' type.
- TyCCharThe C 'char' type.
- TyCChar16The C++11 'char16_t' type, which has UTF-16 encoding.
- TyCChar32The C++11 'char32_t' type, which has UTF-32 encoding.
- TyCChar8The C++20 'char8_t' type, which has UTF-8 encoding.
- TyCDoubleThe C 'double' type.
- TyCFloatThe C 'float' type.
- TyCFloat16The C '_Float16' type.
- TyCInt
- TyCLong
- TyCLongDouble
- TyCLongLongThe C 'long long' type.
- TyCShortThe C 'short' type.
Show 43 more
- TyCSignedCharThe C 'signed char' type.
- TyCUnsignedCharThe C 'unsigned char' type.
- TyCUnsignedInt
- TyCUnsignedLong
- TyCUnsignedLongLongThe C 'unsigned long long' type.
- TyCUnsignedShortThe C 'unsigned short' type.
- TyCWideChar
- TyCodableA type that can convert itself into and out of an external representation.
- TyConcurrentValue
- TyCountableClosedRange
- TyCountablePartialRangeFrom
- TyCountableRange
- TyDictionaryIndex
- TyDictionaryIterator
- TyDictionaryLiteral
- TyEnumeratedIterator
- TyExtendedGraphemeClusterTypeThe default type for an otherwise-unconstrained Unicode extended
- TyFlattenCollection
- TyFloat32A 32-bit floating point type.
- TyFloat64A 64-bit floating point type.
- TyFloatLiteralTypeThe default type for an otherwise-unconstrained floating-point literal.
- TyIntegerLiteralTypeThe default type for an otherwise-unconstrained integer literal.
- TyLazyCollectionA collection containing the same elements as a `Base` collection,
- TyLazyDropWhileCollectionA lazy wrapper that includes the elements of an underlying
- TyLazyFilterCollectionA lazy `Collection` wrapper that includes the elements of an
- TyLazyMapCollectionA `Collection` whose elements consist of those in a `Base`
- TyLazyPrefixWhileCollectionA lazy collection wrapper that includes the initial consecutive
- TyPlaygroundQuickLookThe sum of types that can be used as a Quick Look representation.
- TySetIndex
- TySetIterator
- TyStringLiteralTypeThe default type for an otherwise-unconstrained string literal.
- TyUTF16
- TyUTF32
- TyUTF8
- TyUnboundedRangeThe type of an unbounded range operator.
- TyUnfoldFirstSequenceThe return type of `sequence(first:next:)`.
- TyUnicodeScalar
- TyUnicodeScalarTypeThe default type for an otherwise-unconstrained unicode scalar literal.
- TyUnsafeConcurrentValue
- TyVoidThe return type of functions that don't explicitly specify a return type,
- TyAnyActorCommon marker protocol providing a shared "base" for both (local) `Actor`
- TyPartialAsyncTask
- TyUnsafeThrowingContinuation