Reference

public struct Reference : Codable
extension Reference: Equatable
extension Reference: Hashable

Represents an attribute name or path expression identifying a value within a Context.

This can be used to retrieve a value with LDContext.getValue(_:), or to identify an attribute or nested value that should be considered private with LDContextBuilder.addPrivateAttribute(_:) (the SDK configuration can also have a list of private attribute references).

This is represented as a separate type, rather than just a string, so that validation and parsing can be done ahead of time if an attribute reference will be used repeatedly later (such as in flag evaluations).

If the string starts with ‘/’, then this is treated as a slash-delimited path reference where the first component is the name of an attribute, and subsequent components are the names of nested JSON object properties. In this syntax, the escape sequences “~0” and “~1” represent ‘~’ and ‘/’ respectively within a path component.

If the string does not start with ‘/’, then it is treated as the literal name of an attribute.

For instance, if the JSON representation of a context is as follows–

{
  "kind": "user",
  "key": "123",
  "name": "xyz",
  "address": {
    "street": "99 Main St.",
    "city": "Westview"
  },
  "a/b": "ok"
}

– then

  • Reference(“name”) or Reference(“/name”) would refer to the value “xyz”
  • Reference(“/address/street”) would refer to the value “99 Main St.”
  • Reference(“a/b”) or Reference(“/a~1b”) would refer to the value “ok”
  • Construct a new Reference.

    This constructor always returns a Reference that preserves the original string, even if validation fails, so that serializing the Reference to JSON will produce the original string.

    Declaration

    Swift

    public init(_ value: String)
  • Undocumented

    Declaration

    Swift

    public init(literal value: String)
  • Declaration

    Swift

    public init(from decoder: Decoder) throws
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • Returns whether or not the reference provided is valid.

    Declaration

    Swift

    public func isValid() -> Bool
  • If the reference is invalid, this method will return an error description; otherwise, it will return an empty string.

    Declaration

    Swift

    public func getError() -> ReferenceError?
  • Returns raw string that was passed into constructor.

    Declaration

    Swift

    public func raw() -> String
  • Declaration

    Swift

    public static func == (lhs: Reference, rhs: Reference) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)