A tuple in Swift is a lightweight, finite, and ordered compound type that groups multiple values of potentially disparate types into a single entity. As a structural value type, a tuple is passed by copy, and its arity (number of elements) and element types are statically determined at compile time. Unlike nominal types (classes, structs, enums), tuples do not support methods, custom initializers, or protocol conformance.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax and Initialization
Tuples are defined using a comma-separated list of types or values enclosed in parentheses. They can be instantiated with or without explicit element labels.Element Access
Tuple elements are accessed either by zero-based positional indices or by their explicit labels using dot notation.Decomposition (Destructuring)
A tuple’s contents can be extracted and bound to individual constants or variables in a single operation. The wildcard pattern (_) can be used to ignore specific elements during decomposition.
Mutability
If a tuple is assigned to a variable (var), its individual elements can be mutated. However, the tuple’s structural signature—its arity and the specific types of its elements—is immutable.
Type Aliasing
Because tuples are structural types, complex tuple signatures can become verbose. Thetypealias keyword is used to assign a nominal identifier to a tuple structure for strict type checking and readability.
Equality and Comparison
Tuples do not conform to protocols, meaning a tuple cannot be passed to a generic function constrained to<T: Equatable> or <T: Comparable>. However, the Swift standard library provides overloaded equality (==, !=) and comparison (<, <=, >, >=) operators for tuples up to an arity of 6, provided all constituent elements support these operations. Comparison is evaluated lexicographically (left-to-right).
(a: 1, b: 2) is considered equal to (x: 1, y: 2).
Master Swift with Deep Grasping Methodology!Learn More





