Accesses a contiguous subrange of the collection’s elements.
- Xcode 10.2+
- Swift Standard Library
A range of the collection’s indices. The bounds of the range must be valid indices of the collection.
For example, using a
Partial range expression with an array accesses the subrange from the start of the range expression until the end of the array.
The accessed slice uses the same indices for the same elements as the original collection. This example searches
streets for one of the strings in the slice, and then uses that index in the original array.
Always use the slice’s
start property instead of assuming that its indices start at a particular value. Attempting to access an element by using an index outside the bounds of the slice may result in a runtime error, even if that index is valid for the original collection.