Attribute

public struct Attribute : Hashable, Codable
extension Attribute: ExpressibleBySyntax
extension Attribute: CustomStringConvertible

A declaration attribute.

Attributes provide additional information about a declaration. For example, the @discardableResult attribute indicates that a function may be called without using the result.

  • The attribute name.

    An attribute’s name is everything after the at-sign (@) and before the argument clause. For example, the name of the attribute in the following declaration is "available":

    @available(macOS 10.15, iOS 13, *)
    

    Declaration

    Swift

    public let name: String
  • The attribute’s arguments, if any.

    Declaration

    Swift

    public let arguments: [Argument]
  • An attribute argument.

    Certain attributes take one or more arguments, each of which have a value and optional name. For example, the following attribute declaration has three arguments:

    @available(*, unavailable, message: "🚫")
    
    • The first argument is unnamed and has the value "*"
    • The second argument is unnamed and has the value "unavailable"
    • The third argument has the name “renamed” and the value "🚫"
    See more

    Declaration

    Swift

    public struct Argument : Hashable, Codable
    extension Attribute.Argument: CustomStringConvertible

ExpressibleBySyntax

  • Creates an instance initialized with the given syntax node.

    Declaration

    Swift

    public init(_ node: AttributeSyntax)

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }