Solve complex problems, and write high-performance, readable code. Access the fundamental protocols, data types, and algorithms common to all Swift programs.
Language
Swift
Overview
The Swift standard library defines a base layer of functionality for writing Swift programs, including:
Protocols used to provide implementations that would otherwise require boilerplate code, such as OptionSet.
Many language features have a corresponding protocol—any type that conforms to the protocol can be used with that feature. For example, a for-in loop can iterate over the elements of any value whose type conforms to the Sequence protocol, and any type that conforms to the ExpressibleByStringLiteral protocol can have values assigned from string literals.
By default, the standard library guarantees memory safety. Many functions and methods document the requirements that must be satisfied by the caller, such as an array index being valid; memory safety is guaranteed even if a requirement is violated. However, violating a requirement can trigger a runtime error. APIs that include the word “unsafe” in their name let you explicitly disable safety checks in places where you need the additional performance. It’s your responsibility to verify the memory safety of code that uses unsafe APIs. Memory safety is also not guaranteed if there is a race condition in multithreaded code.
Many functions and methods have documented performance characteristics. These characteristics are guaranteed only when all participating protocols' performance expectations are satisfied. If a participating type fails to satisfy these expectations, the functions and methods work as documented, except for their performance guarantees. Types provided by the standard library meet all performance expectations of the protocols they adopt, except where explicitly noted.
A Collection whose elements consist of those in a BaseCollection passed through a transform function returning Element. These elements are computed lazily, each time they’re read, by calling the transform function on a base element.
A Collection whose elements consist of those in a BaseCollection passed through a transform function returning Element. These elements are computed lazily, each time they’re read, by calling the transform function on a base element.
The IteratorProtocol used by MapSequence and MapCollection. Produces each element by passing the output of the BaseIteratorProtocol through a transform function returning Element.
A Collection whose elements consist of those in a BaseCollection passed through a transform function returning Element. These elements are computed lazily, each time they’re read, by calling the transform function on a base element.
A Sequence whose elements consist of those in a BaseSequence passed through a transform function returning Element. These elements are computed lazily, each time they’re read, by calling the transform function on a base element.
Contains a buffer object, and provides access to an instance of Header and contiguous storage for an arbitrary number of Element instances stored in that buffer.
A raw pointer for accessing data of type Pointee. This type provides no automated memory management, and therefore must be handled with great care to ensure safety.
A raw pointer for accessing untyped data. This provides no automatic memory management, no type safety, and no alignment guarantees. This implements Strideable to provide a view of byte-addressable memory.
A raw pointer for accessing data of type Pointee. This type provides no automated memory management, and therefore must be handled with great care to ensure safety.
A raw pointer for accessing untyped data. This provides no automatic memory management, no type safety, and no alignment guarantees. This implements Strideable to provide a view of byte-addressable memory.