A range expression that represents the entire range of a collection.
SDK
- Xcode 9.0+
Framework
- Swift Standard Library
Declaration
Overview
You can use the unbounded range operator (...
) to create a slice of a collection that contains all of the collection’s elements. Slicing with an unbounded range is essentially a conversion of a collection instance into its slice type.
For example, the following code declares count
, a function that finds the number of changes required to change one word or phrase into another. The function uses a recursive approach to perform the same comparisons on smaller and smaller pieces of the original strings. In order to use recursion without making copies of the strings at each step, count
uses Substring
, a string’s slice type, for its parameters.
To call count
with two strings, use an unbounded range in each string’s subscript.