iOS Developer Library — Prerelease

Developer

Swift Standard Library Reference

The Swift Standard Library

Structures   Enumerations   Classes   Protocols   Other Reference  

The Swift standard library defines a base layer of functionality for writing Swift programs, including:

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 SequenceType protocol, and any type that conforms to the StringLiteralConvertible 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.

Structures

AnyBidirectionalCollection

A type-erased wrapper over any collection with indices that support bidirectional traversal.

AnyBidirectionalIndex

A wrapper over an underlying BidirectionalIndexType that hides the specific underlying type.

AnyForwardCollection

A type-erased wrapper over any collection with indices that support forward traversal.

AnyForwardIndex

A wrapper over an underlying ForwardIndexType that hides the specific underlying type.

AnyRandomAccessCollection

A type-erased wrapper over any collection with indices that support random access traversal.

AnyRandomAccessIndex

A wrapper over an underlying RandomAccessIndexType that hides the specific underlying type.

AnySequence

A type-erased sequence.

Array

The Array structure is an ordered, random-access collection of elements of a given type.

ArraySlice

The Array-like type that represents a sub-sequence of any Array, ContiguousArray, or other ArraySlice.

AutoreleasingUnsafeMutablePointer

A mutable pointer-to-ObjC-pointer argument.

Bool

A value type whose instances are either true or false.

COpaquePointer

A wrapper around an opaque C pointer.

CVaListPointer

The corresponding Swift type to va_list in imported C APIs.

Character

Character represents some Unicode grapheme cluster as defined by a canonical, localized, or otherwise tailored segmentation algorithm.

CharacterView.Index

A character position.

ClosedInterval

A closed IntervalType, which contains both its start and its end.

CollectionOfOne

A collection containing a single element of type Element.

ContiguousArray

A fast, contiguously-stored array of Element.

Dictionary

A hash-based mapping from Key to Value instances.

DictionaryGenerator

A generator over the members of a Dictionary<Key, Value>.

DictionaryIndex

Used to access the key-value pairs in an instance of Dictionary<Key, Value>.

DictionaryLiteral

Represent the ability to pass a dictionary literal in function signatures.

Double

EmptyCollection

A collection whose element type is Element but that is always empty.

EmptyGenerator

A generator that never produces an element.

EnumerateGenerator

The GeneratorType for EnumerateSequence.

EnumerateSequence

The SequenceType returned by enumerate().

FilterCollection

A lazy CollectionType wrapper that includes the elements of an underlying collection that satisfy a predicate.

FilterCollectionIndex

The Index used for subscripting a FilterCollection.

FilterGenerator

The GeneratorType used by FilterSequence and FilterCollection.

FilterSequence

The lazy SequenceType returned by filter(c) where c is a SequenceType.

Float

GeneratorOfOne

A generator that produces one or fewer instances of Element.

GeneratorSequence

A sequence built around a generator of type G.

HalfOpenInterval

A half-open IntervalType, which contains its start but not its end.

IndexingGenerator

A generator for an arbitrary collection.

Int

A 32-bit signed integer value type.

Int16

A 16-bit signed integer value type.

Int32

A 32-bit signed integer value type.

Int64

A 64-bit signed integer value type.

Int8

A 8-bit signed integer value type.

LazyBidirectionalCollection

A collection that forwards its implementation to an underlying collection instance while exposing lazy computations as methods.

LazyForwardCollection

A collection that forwards its implementation to an underlying collection instance while exposing lazy computations as methods.

LazyRandomAccessCollection

A collection that forwards its implementation to an underlying collection instance while exposing lazy computations as methods.

LazySequence

A sequence that forwards its implementation to an underlying sequence instance while exposing lazy computations as methods.

ManagedBufferPointer

Contains a buffer object, and provides access to an instance of Value and contiguous storage for an arbitrary number of Element instances stored in that buffer.

MapCollection

A CollectionType whose elements consist of those in a Base CollectionType passed through a transform function returning Element.

MapGenerator

The GeneratorType used by MapSequence and MapCollection.

MapSequence

A SequenceType whose elements consist of those in a Base SequenceType passed through a transform function returning Element.

Mirror

Representation of the sub-structure and optional "display style" of any arbitrary subject instance.

ObjectIdentifier

A unique identifier for a class instance or metatype.

PermutationGenerator

A generator that adapts a collection C and any sequence of its Index type to present the collection's elements in a permuted order.

Range

A collection of consecutive discrete index values.

RangeGenerator

A generator over the elements of Range<Element>.

RawByte

A byte-sized thing that isn't designed to interoperate with any other types; it makes a decent parameter to UnsafeMutablePointer<Memory> when you just want to do bytewise pointer arithmetic.

Repeat

A collection whose elements are all identical Elements.

ReverseCollection

The lazy CollectionType returned by reverse(c) where c is a CollectionType with an Index conforming to BidirectionalIndexType.

ReverseIndex

A wrapper for a BidirectionalIndexType that reverses its direction of traversal.

ReverseRandomAccessCollection

The lazy CollectionType returned by reverse(c) where c is a CollectionType with an Index conforming to RandomAccessIndexType.

ReverseRandomAccessIndex

A wrapper for a RandomAccessIndexType that reverses its direction of traversal.

Set

A collection of unique Element instances with no defined ordering.

SetGenerator

A generator over the members of a Set<Element>.

SetIndex

Used to access the members in an instance of Set<Element>.

Slice

StaticString

An simple string designed to represent text that is "knowable at compile-time".

StrideThrough

A SequenceType of values formed by striding over a closed interval.

StrideThroughGenerator

A GeneratorType for StrideThrough<Element>.

StrideTo

A SequenceType of values formed by striding over a half-open interval.

StrideToGenerator

A GeneratorType for StrideTo<Element>.

String

An arbitrary Unicode string value.

String.CharacterView

A String's collection of Characters (extended grapheme clusters) elements.

String.UTF16View

A collection of UTF-16 code units that encodes a String value.

String.UTF16View.Index

String.UTF8View

A collection of UTF-8 code units that encodes a String value.

String.UTF8View.Index

A position in a String.UTF8View.

String.UnicodeScalarView

A collection of Unicode scalar values that encode a String .

String.UnicodeScalarView.Generator

A type whose instances can produce the elements of this sequence, in order.

String.UnicodeScalarView.Index

A position in a String.UnicodeScalarView.

UInt

A 32-bit unsigned integer value type.

UInt16

A 16-bit unsigned integer value type.

UInt32

A 32-bit unsigned integer value type.

UInt64

A 64-bit unsigned integer value type.

UInt8

A 8-bit unsigned integer value type.

UTF16

A codec for UTF-16.

UTF32

A codec for UTF-32.

UTF8

A codec for UTF-8.

UnicodeScalar

A Unicode scalar value.

Unmanaged

A type for propagating an unmanaged object reference.

UnsafeBufferPointer

A non-owning pointer to buffer of Elements stored contiguously in memory, presenting a Collection interface to the underlying elements.

UnsafeBufferPointerGenerator

A generator for the elements in the buffer referenced by UnsafeBufferPointer or UnsafeMutableBufferPointer.

UnsafeMutableBufferPointer

A non-owning pointer to buffer of mutable Elements stored contiguously in memory, presenting a Collection interface to the underlying elements.

UnsafeMutablePointer

A pointer to an object of type Memory.

UnsafePointer

A pointer to an object of type Memory.

Zip2Generator

A generator for Zip2Sequence.

Zip2Sequence

A sequence of pairs built out of two underlying sequences, where the elements of the ith pair are the ith elements of each underlying sequence.

Enumerations

Bit

A RandomAccessIndexType that has two possible values.

FloatingPointClassification

The set of possible IEEE 754 "classes"

ImplicitlyUnwrappedOptional

An optional type that allows implicit member access (via compiler magic).

Mirror.AncestorRepresentation

Representation of ancestor classes.

Mirror.DisplayStyle

A suggestion of how a Mirror's is to be interpreted.

Optional

PlaygroundQuickLook

The sum of types that can be used as a quick look representation.

Process

UnicodeDecodingResult

The result of one Unicode decoding step.

Classes

AnyGenerator

An abstract GeneratorType base class over Element elements.

NonObjectiveCBase

A common base class for classes that need to be non-@objc, recognizably in the type system.

ManagedProtoBuffer

A base class of ManagedBuffer<Value,Element>, used during instance creation.

ManagedBuffer

A class whose instances contain a property of type Value and raw storage for an array of Element, whose size is determined at instance creation.

VaListBuilder

An object that can manage the lifetime of storage backing a CVaListPointer.

Protocols

AbsoluteValuable

A type that supports an "absolute value" function.

AnyCollectionType

A protocol for AnyForwardCollection<Element>, AnyBidirectionalCollection<Element>, and AnyRandomAccessCollection<Element>.

AnyObject

ArrayLiteralConvertible

Conforming types can be initialized with array literals.

BidirectionalIndexType

An index that can step backwards via application of its predecessor() method.

BitwiseOperationsType

A set type with O(1) standard bitwise operators.

BooleanLiteralConvertible

Conforming types can be initialized with the boolean literals true and false.

BooleanType

A type that represents a boolean value.

CVarArgType

Instances of conforming types can be encoded, and appropriately passed, as elements of a C va_list.

CollectionType

A multi-pass sequence with addressable positions.

Comparable

Instances of conforming types can be compared using relational operators, which define a strict total order.

CustomDebugStringConvertible

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

CustomLeafReflectable

A type that explicitly supplies its own Mirror but whose descendant classes are not represented in the Mirror unless they also override customMirror().

CustomPlaygroundQuickLookable

A type that explicitly supplies its own PlaygroundQuickLook.

CustomReflectable

A type that explicitly supplies its own Mirror.

CustomStringConvertible

A type with a customized textual representation.

DictionaryLiteralConvertible

Conforming types can be initialized with dictionary literals.

Equatable

Instances of conforming types can be compared for value equality using operators == and !=.

ErrorType

ExtendedGraphemeClusterLiteralConvertible

Conforming types can be initialized with string literals containing a single Unicode extended grapheme cluster.

FloatLiteralConvertible

Conforming types can be initialized with floating point literals.

FloatingPointType

A set of common requirements for Swift's floating point types.

ForwardIndexType

Represents a discrete value in a series, where a value's successor, if any, is reachable by applying the value's successor() method.

GeneratorType

Encapsulates iteration state and interface for iteration over a sequence.

Hashable

Instances of conforming types provide an integer hashValue and can be used as Dictionary keys.

Indexable

IntegerArithmeticType

The common requirements for types that support integer arithmetic.

IntegerLiteralConvertible

Conforming types can be initialized with integer literals.

IntegerType

A set of common requirements for Swift's integer types.

IntervalType

An interval over a Comparable type.

MirrorPathType

A protocol for legitimate arguments to Mirror's descendant method.

MutableCollectionType

A collection that supports subscript assignment.

MutableSliceable

A collection with mutable slices.

NilLiteralConvertible

Conforming types can be initialized with nil.

OptionSetType

Supplies convenient conformance to SetAlgebraType for any type whose RawValue is a BitwiseOperationsType.

OutputStreamType

A target of text streaming operations.

RandomAccessIndexType

An index that can be offset by an arbitrary number of positions, and can measure the distance to any reachable value, in O(1).

RangeReplaceableCollectionType

A collection that supports replacement of an arbitrary subRange of elements with the elements of another collection.

RawRepresentable

A type that can be converted to an associated "raw" type, then converted back to produce an instance equivalent to the original.

SequenceType

A type that can be iterated with a for...in loop.

SetAlgebraType

A generalized set whose distinct elements are not necessarily disjoint.

SignedIntegerType

A set of common requirements for Swift's signed integer types.

SignedNumberType

Instances of conforming types can be subtracted, arithmetically negated, and initialized from 0.

Streamable

A source of text streaming operations.

Strideable

Conforming types are notionally continuous, one-dimensional values that can be offset and measured.

StringInterpolationConvertible

Conforming types can be initialized with string interpolations containing \(...) clauses.

StringLiteralConvertible

Conforming types can be initialized with arbitrary string literals.

UnicodeCodecType

A Unicode encoding scheme.

UnicodeScalarLiteralConvertible

Conforming types can be initialized with string literals containing a single Unicode scalar value.

UnsignedIntegerType

A set of common requirements for Swift's unsigned integer types.

_Incrementable

This protocol is an implementation detail of ForwardIndexType; do not use it directly.

Other Reference

Swift Standard Library Functions Reference

Swift Standard Library Operators Reference

Swift Standard Library Type Aliases Reference