Environment
public class Environment : Collection, ExpressibleByDictionaryLiteral
A class that is used to capture and represent the os environment variables.
This class can be passed to TraceLog.configure(mode:writers:environment:)
methods to configure it using the
current Environment settings.
Environment is also like a Swift Dictionary
See also
TraceLog.configure(mode:writers:environment:)
for usage.
See also
TraceLog.configure(writers:environment:)
for usage.
-
Creates a new Environment instance from a dictionary literal.
The following example creates an Environment instance with the the elements of the dictionary literal:
let environment: Environment = ["LOG_ALL": "ERROR", "LOG_TAG_MyTag": "TRACE1"]
Parameters
dictionaryLiteral
A dictionary literal representing the environment variables that will be available to TraceLog.
-
Creates a new Environment instance with any collection type with an element type of [
Environment.Key
:Environment.Value
].The following example creates an Environment instance with the contents of the dictionary type values:
let values: [String : String] = ["LOG_ALL": "ERROR", "LOG_TAG_MyTag": "TRACE1"] let environment = Environment(values)
Declaration
Parameters
elements
Any
Collection
type whose Element is equal to [Environment.Key
:Environment.Value
]. -
Creates a new Environment instance and fills it with the variable set in the current OS environment.
The following example creates an Environment instance with the current contents of the OS environment:
let environment = Environment()
Declaration
Swift
public init()
-
Accesses the element at the specified position.
The following example accesses an element of an Environment through its subscript to print its value:
let environment: Environment = ["LOG_ALL": "ERROR", "LOG_TAG_MyTag": "TRACE1"] print(environment[1]) // Prints "TRACE1"
Parameters
position
The position of the element to access.
position
must be a valid index of the Environment that is not equal to theendIndex
property. -
Set or get the element with the specified key.
The following example accesses an element of an Environment through its subscript to get and print its value:
let environment: Environment = ["LOG_ALL": "ERROR", "LOG_TAG_MyTag": "TRACE1"] print(environment["LOG_ALL"]) // Prints "ERROR"
The following example accesses an element of an Environment through its subscript to set and print its value:
environment["LOG_TAG_AnotherTag"] = "INFO" print(environment["LOG_TAG_AnotherTag"]) // Prints "INFO"
Parameters
key
The key of the element to access.
-
Declaration
Swift
public typealias Key = String
-
Declaration
Swift
public typealias Value = String