Swift Standard Library

Solve complex problems and write high-performance, readable code.


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


Values and Collections

Numbers and Basic Values

Model data with numbers, Boolean values, and other fundamental types.

Strings and Text

Work with text using Unicode-safe strings.


Store and organize data using arrays, dictionaries, sets, and other data structures.

Tools for Your Types

Basic Behaviors

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

Encoding, Decoding, and Serialization

Serialize and deserialize instances of your types with implicit or customized encoding.

Initialization with Literals

Allow values of your type to be expressed using different kinds of literals.

Programming Tasks

Input and Output

Print values to the console, read from and write to text streams, and use command line arguments.

Debugging and Reflection

Fortify your code with runtime checks, and examine your values' runtime representation.

Key-Path Expressions

Use key-path expressions to access properties dynamically.

Manual Memory Management

Allocate and manage memory manually.

Type Casting and Existential Types

Perform casts between types or represent values of any type.

C Interoperability

Use imported C types or call C variadic functions.

Operator Declarations

Work with prefix, postfix, and infix operators.

See Also

Standard Library

struct Int

A signed integer value type.

struct Double

A double-precision, floating-point value type.

struct String

A Unicode string value that is a collection of characters.

struct Array

An ordered, random-access collection.

struct Dictionary

A collection whose elements are key-value pairs.