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

Initializer

mattt edited this page Mar 28, 2020 · 9 revisions

Initializer

An initializer declaration.

public struct Initializer: Declaration, Hashable, Codable

Inheritance

Codable, Hashable, Declaration

Initializers

init(_:)

Creates an instance initialized with the given syntax node.

public init(_ node: InitializerDeclSyntax)

Properties

genericRequirements

The generic parameter requirements for the declaration.

let genericRequirements: [GenericRequirement]

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

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

throwsOrRethrowsKeyword

The throws or rethrows keyword, if any.

let throwsOrRethrowsKeyword: String?

attributes

The declaration attributes.

let attributes: [Attribute]

modifiers

The declaration modifiers.

let modifiers: [Modifier]

keyword

The declaration keyword ("associatedtype").

let keyword: String

parameters

The initializer inputs.

let parameters: [Function.Parameter]

genericParameters

The generic parameters for the declaration.

let genericParameters: [GenericParameter]

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

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

description

var description: String

optional

Whether the initializer is optional.

let optional: Bool