The position of the element to access. position
must be a valid index of the collection that is not equal to the end
property.
Instance Subscript
subscript(_:)
Accesses the element at the specified position.
指定された位置での要素にアクセスします。
Availability 有効性
- iOS 15.0+
- iPadOS 15.0+
- macOS 12.0+
- Mac Catalyst 15.0+
- tvOS 15.0+
- watchOS 8.0+
Technology
- Swift
UI
Declaration 宣言
Available when
Value
conforms to MutableCollection
.Parameters パラメータ
position
Index
Overview 概要
The following example accesses an element of an array through its subscript to print its value:
var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
print(streets[1])
// Prints "Bryant"
You can subscript a collection with any valid index other than the collection’s end index. The end index refers to the position one past the last element of a collection, so it doesn’t correspond with an element.
Complexity
O(1)