Accesses the contiguous subrange of the collection’s elements specified by a range expression.
- iOS 7.0+
- macOS 10.9+
- UIKit for Mac 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
- Xcode 10.0+
A range of the collection’s indices. The bounds of the range must be valid indices of the collection.
The range expression is converted to a concrete subrange relative to this 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 uses. 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’s indices may result in a runtime error, even if that index is valid for the original collection.