Contents

subscript(_:)

Accesses a collection element by index, for comparison with a known value.

Declaration

subscript<T>(index: Int) -> T where T : IntentValueConvertible { get throws }

Overview

The code below shows the syntactic sugar and the equivalent, desugared, subscript syntax.

let result = try await intent.run() // Expected an array as result value

try result.value[0] == "My Name"

If the property’s value isn’t an instance of the type T, this subscript throws an error.

For more information about dynamic-member syntax, see dynamicMemberLookup in The Swift Programming Language.