Standard Library

The Swift standard library defines a base layer of functionality for writing Swift programs. Documentation for the standard library is presently hosted on the Apple Developer website.

The Swift standard library, along with its tests and inline documentation, are a part of the main Swift repository.

Standard Library Preview Package

The Standard Library Preview package provides early access to new additions to the standard library. When new standard library APIs that can be implemented as a standalone library are accepted through the Swift Evolution process, they are published as individual packages and included in the preview package, which acts as an umbrella library. The preview package currently includes the following individual packages:

Package Description
SE0270_RangeSet Operations on noncontiguous subranges of collections, such as subranges(where:) and moveSubranges(_:to:), as well as the supporting RangeSet type.
SE0288_IsPower Extends BinaryInteger with an isPower(of:) method that returns whether an integer is a power of another.

Standard Library Design

The Swift standard library encompasses a number of data types, protocols and functions, including fundamental data types (e.g., Int, Double), collections (e.g., Array, Dictionary) along with the protocols that describe them and algorithms that operate on them, characters and strings, and low-level primitives (e.g., UnsafeMutablePointer). The implementation of the standard library resides in the stdlib/public subdirectory within the Swift repository, which is further subdivided into:

The Swift standard library is written in Swift, but because it is the lowest-level Swift code in the stack—responsible for implementing the core data types on which other Swift code is built—it is a bit different from normal Swift code. Some of the differences include: