← Back to Documentation Home

STRUCT

Context

public struct Context

Context holds all the parameters needed to make decisions about experiments

Properties

count

public var count: Int

Get the number of parameters - Returns: The count of parameters

isEmpty

public var isEmpty: Bool

Check if context is empty - Returns: True if no parameters are set

Methods

init(_:)

public init(_ params: [ContextParam] = [])

addParam(_:)

public mutating func addParam(_ param: ContextParam)

Add a context parameter - Parameter param: The context parameter to add

Parameters

Name Description
param The context parameter to add

getParam(_:)

public func getParam(_ key: String) -> ContextParam?

Get a context parameter by its key - Parameter key: The key of the parameter - Returns: The context parameter if found

Parameters

Name Description
key The key of the parameter

getParamValue(_:)

public func getParamValue(_ key: String) -> Any?

Get a context parameter value by its key - Parameter key: The key of the parameter - Returns: The parameter value if found

Parameters

Name Description
key The key of the parameter

getParamValueOrEmptyString(_:)

public func getParamValueOrEmptyString(_ key: String) -> String

Get a context parameter value as string, or empty string if not found - Parameter key: The key of the parameter - Returns: The parameter value as string or empty string

Parameters

Name Description
key The key of the parameter

getAllParams()

public func getAllParams() -> [String: ContextParam]

Get all parameters - Returns: Dictionary of all parameters

validate()

public func validate() throws

Validate all context parameters - Throws: ContextValidationError if any parameter is invalid

toArray()

public func toArray() -> [String: Any]

Convert context to array format for API requests - Returns: Dictionary representation of the context

getKeys()

public func getKeys() -> [String]

Get all parameter keys - Returns: Array of all parameter keys

hasParam(_:)

public func hasParam(_ key: String) -> Bool

Check if context has a specific parameter - Parameter key: The key to check for - Returns: True if the parameter exists

Parameters

Name Description
key The key to check for

removeParam(_:)

public mutating func removeParam(_ key: String)

Remove a parameter by key - Parameter key: The key of the parameter to remove

Parameters

Name Description
key The key of the parameter to remove

clearAll()

public mutating func clearAll()

Clear all parameters