A type that iterates over a collection using its indices.
- Xcode 8.0+
- Swift Standard Library
Indexing type is the default iterator for any collection that doesn’t declare its own. It acts as an iterator by using a collection’s indices to step over each value in the collection. Most collections in the standard library use
Indexing as their iterator.
By default, any custom collection type you create will inherit a
make method that returns an
Indexing instance, making it unnecessary to declare your own. When creating a custom collection type, add the minimal requirements of the
Collection protocol: starting and ending indices and a subscript for accessing elements. With those elements defined, the inherited
make method satisfies the requirements of the
Here’s an example of a type that declares the minimal requirements for a collection. The
Collection structure is a fixed-size collection that always holds two elements of a specific type.
Collection doesn’t define its own
make method or
Iterator associated type, it uses the default iterator type,
Indexing. This example shows how a
Collection instance can be created holding the values of a point, and then iterated over using a