Set

@frozen
extension Set: EnvironmentStringConvertible where Element: EnvironmentStringConvertible
  • Instantiates a Set<Element> from an environment variable string representation where the Element conforms to EnvironmentStringConvertible.

    Elements must be comma (,) separated in the string representation.

    let strings = Set<String>(environmentString: "one,one,two,three")
    print(strings)
    // Prints "Optional(Set(["three", "two", "one"]))"
    
    let numbers = Set<Int>(environmentString: "1,1,2,3")
    print(numbers)
    // Prints "Optional(Set([1, 3, 2]))"
    

    This enables setting and getting a set using the Environment.

    Environment.environment.NAMES = Set<String>(["bob", "billy"])
    // Sets a string value of "bob,billy"
    
    let names: Set<String>? = Environment.environment.NAMES
    // Gets a set of Set(["bob", "billy"])
    

    Declaration

    Swift

    public init?(environmentString: String)

    Parameters

    environmentString

    The string representation of the environment variable.

  • The environment variable string representation.

    Elements are comma (,) separated.

    let numbers = Set([1,2,3])
    print(numbers.environmentString)
    // Prints "1,2,3"
    

    Declaration

    Swift

    public var environmentString: String { get }