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

Function_Parameter

mattt edited this page Jan 26, 2020 · 6 revisions

Function.Parameter

A function parameter.

public struct Parameter: Hashable, Codable

This type can also be used to represent initializer parameters and associated values for enumeration cases.

Inheritance

Hashable, Codable, CustomStringConvertible, ExpressibleBySyntax

Initializers

init(_:)

Creates an instance initialized with the given syntax node.

public init(_ node: FunctionParameterSyntax)

Properties

attributes

The declaration attributes.

let attributes: [Attribute]

firstName

The first, external name of the parameter.

let firstName: String?

For example, given the following function declaration, the first parameter has a firstName equal to nil, and the second parameter has a firstName equal to "by":

func increment(_ number: Int, by amount: Int = 1)

secondName

The second, internal name of the parameter.

let secondName: String?

For example, given the following function declaration, the first parameter has a secondName equal to "number", and the second parameter has a secondName equal to "amount":

func increment(_ number: Int, by amount: Int = 1)

type

The type identified by the parameter.

let type: String?

For example, given the following function declaration, the first parameter has a type equal to "Person", and the second parameter has a type equal to "String":

func greet(_ person: Person, with phrases: String...)

variadic

Whether the parameter accepts a variadic argument.

let variadic: Bool

For example, given the following function declaration, the second parameter is variadic:

func greet(_ person: Person, with phrases: String...)

defaultArgument

The default argument of the parameter.

let defaultArgument: String?

For example, given the following function declaration, the second parameter has a default argument equal to "1".

func increment(_ number: Int, by amount: Int = 1)

description

var description: String