GenericRequirement

public struct GenericRequirement : Hashable, Codable
extension GenericRequirement: CustomStringConvertible

A generic requirement.

A generic type or function declaration may specifying one or more requirements in a generic where clause before the opening curly brace ({) its body. Each generic requirement establishes a relation between two type identifiers.

For example, the following declaration specifies two generic requirements:

func difference<C1: Collection, C2: Collection>(between lhs: C1, and rhs: C2) -> [C1.Element]
   where C1.Element: Equatable, C1.Element == C2.Element
  • The first generic requirement establishes a conformance relation between the generic types identified by "C1.Element" and "Equatable"
  • The second generic requirement establsihes a sameType relation between the generic types identified by "C1.Element" and "C2.Element"
  • A relation between the two types identified in the generic requirement.

    For example, the declaration struct S<T: Equatable> has a single generic requirement that the type identified by "T" conforms to the type identified by "Equatable".

    See more

    Declaration

    Swift

    public enum Relation : String, Hashable, Codable
  • The relation between the two identified types.

    Declaration

    Swift

    public let relation: Relation
  • The identifier for the left-hand side type.

    Declaration

    Swift

    public let leftTypeIdentifier: String
  • The identifier for the right-hand side type.

    Declaration

    Swift

    public let rightTypeIdentifier: String
  • Creates and returns generic requirements initialized from a generic requirement list syntax node.

    Declaration

    Swift

    public static func genericRequirements(from node: GenericRequirementListSyntax?) -> [GenericRequirement]

    Parameters

    from

    The generic requirement list syntax node, or nil.

    Return Value

    An array of generic requirements, or nil if the node is nil.

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }