Function

public struct Function : Declaration, Hashable, Codable
extension Function: ExpressibleBySyntax
extension Function: CustomStringConvertible

A function declaration.

  • 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).

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

    enum A { enum B { static func greet() {} }
    

    Declaration

    Swift

    public let context: String?
  • The declaration attributes.

    Declaration

    Swift

    public let attributes: [Attribute]
  • The declaration modifiers.

    Declaration

    Swift

    public let modifiers: [Modifier]
  • The declaration keyword ("func").

    Declaration

    Swift

    public let keyword: String
  • The function identifier.

    Declaration

    Swift

    public let identifier: String
  • The function signature.

    Declaration

    Swift

    public let signature: Signature
  • The generic parameters for the declaration.

    For example, the following declaration of function f has a single generic parameter whose identifier is "T" and type is "Equatable":

    func f<T: Equatable>(value: T) {}
    

    Declaration

    Swift

    public let genericParameters: [GenericParameter]
  • The generic parameter requirements for the declaration.

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

    func f<T>(value: T) where T: Hashable {}
    

    Declaration

    Swift

    public let genericRequirements: [GenericRequirement]
  • Whether the function is an operator.

    Declaration

    Swift

    public var isOperator: Bool { get }
  • A function signature.

    See more

    Declaration

    Swift

    public struct Signature : Hashable, Codable
    extension Function.Signature: ExpressibleBySyntax
    extension Function.Signature: CustomStringConvertible
  • A function parameter.

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

    See more

    Declaration

    Swift

    public struct Parameter : Hashable, Codable
    extension Function.Parameter: ExpressibleBySyntax
    extension Function.Parameter: CustomStringConvertible

ExpressibleBySyntax

  • Creates an instance initialized with the given syntax node.

    Declaration

    Swift

    public init(_ node: FunctionDeclSyntax)

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }