Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Subscript

mattt edited this page Jan 26, 2020 · 8 revisions

Subscript

A subscript declaration.

public struct Subscript: Declaration, Hashable, Codable

Declaration, Hashable, Codable, ExpressibleBySyntax, CustomStringConvertible

Initializers

init(_:)

Creates an instance initialized with the given syntax node.

public init(_ node: SubscriptDeclSyntax)

Properties

context

A dot-delimited (.) path used to qualify the function name within the module scope of the declaration, or nil if the function isn't nested (that is, declared at the top-level scope of a module).

let context: String?

For example, given the following declaration of a subscript, the context is "A.B":

enum A { struct B { subscript(index: Int) -> Int? { ... } } }

attributes

The declaration attributes.

let attributes: [Attribute]

modifiers

The declaration modifiers.

let modifiers: [Modifier]

keyword

The declaration keyword ("subscript").

let keyword: String

indices

The subscript indices.

let indices: [Function.Parameter]

genericParameters

The generic parameters for the declaration.

let genericParameters: [GenericParameter]

For example, the following subscript declaration has a single generic parameter whose name is "T" and type is "Equatable":

subscript<T: Equatable>(value: T) {}

genericRequirements

The generic parameter requirements for the declaration.

let genericRequirements: [GenericRequirement]

For example, the following subscript declaration has a single requirement that its generic parameter identified as "T" conforms to the type identified as "Hahable":

subscript<T>(value: T) where T: Hashable {}

returnType

The return type of the subscript.

let returnType: String

accessors

The subscript getter and/or setter.

let accessors: [Variable.Accessor]

description

var description: String