Store and organize data using arrays, dictionaries, sets, and other data structures.
Create a collection of all the values in a range by using the half-open (
..<) and closed (
...) range operators.
static func ..< (Self, Self) -> Range<Self>
Returns a half-open range that contains its lower bound but not its upper bound.
A half-open interval from a lower bound up to, but not including, an upper bound.
static func ... (Self, Self) -> Closed
Returns a closed range that contains both of its bounds.
An interval from a lower bound up to, and including, an upper bound.
Create a stride that steps over values between two boundaries using the
func stride<T>(from: T, to: T, by: T
.Stride) -> Stride To<T>
Returns a sequence from a starting value to, but not including, an end value, stepping by the specified amount.
func stride<T>(from: T, through: T, by: T
.Stride) -> Stride Through<T>
Returns a sequence from a starting value toward, and possibly including, an end value, stepping by the specified amount.
These collections can store zero, one, or many of the same element.
Element<T>(T, count: Int) -> Repeated<T>
Creates a collection containing the specified number of the given element.
A collection containing a single element.
A collection whose element type is
Element but that is always empty.
A lightweight collection of key-value pairs.
func sequence<T>(first: T, next: (T) -> T?) -> Unfold
Returns a sequence formed from
first and repeated lazy applications of
func sequence<T, State>(state: State, next: (inout State) -> T?) -> Unfold
Returns a sequence formed from repeated lazy applications of
next to a mutable
Advanced Collection Topics
Write generic code that works with any collection, or build your own collection types.
Use wrappers, indices, and iterators in operations like slicing, flattening, and reversing a collection.
Build your own buffer-backed collection types.