WebcomValue

public protocol WebcomValue

A type to represent a JSON value.

Requirements

API

  • isNull Extension method

    Indicates whether this value is null (not to be confused with the Swift nil keyword).

    Declaration

    Swift

    public var isNull: Bool { get }
  • asString Extension method

    This value as a string or nil when this value is not a string.

    Declaration

    Swift

    public var asString: String? { get }
  • asKey Extension method

    This value as a WebcomKey or nil when this value is not a string.

    Declaration

    Swift

    public var asKey: WebcomKey? { get }
  • asBool Extension method

    This value as a boolean or false when this value is not a boolean.

    Declaration

    Swift

    public var asBool: Bool { get }
  • asBool(default:) Extension method

    Returns this value as a boolean or defaultValue when this value is not a boolean.

    Declaration

    Swift

    public func asBool(default defaultValue: Bool) -> Bool

    Parameters

    defaultValue

    The value to return when this value is not a boolean.

  • asInt Extension method

    This value as an integer or nil when this value is not an integer.

    Declaration

    Swift

    public var asInt: Int? { get }
  • asDouble Extension method

    This value as a double-precision floating-point number or nil when it cannot be represented as a Double.

    Declaration

    Swift

    public var asDouble: Double? { get }
  • asDictionary() Extension method

    This value as a JSON dictionary or nil when this value is not a JSON dictionary.

    Declaration

    Swift

    public func asDictionary() -> [WebcomKey : Any]?
  • asArray() Extension method

    This value as an array or nil when this value is not a JSON dictionary.

    The database does not store arrays, but arrays can be used as input values. When arrays are used, they are replaced in the database with dictionaries whose keys are strings representing the indices ("0", "1" … "9", "10" …).

    The stored dictionary may have originated as an array or as a dictionary with arbitrary keys. This method returns an array by:

    • sorting the keys using the ascending order defined by the WebcomKey type,
    • removing the keys to keep only the values of the children. Otherwise, this method returns nil.

    For example, if this value is the following dictionary:

    ["01": 2, "1": 1, "10": 4, "2": 3, "-1": 0, "a": 11, "A": 8, "e": 12, "é": 16, "€": 17, "f": 13, "z": 14, "Z": 9, "-": 5, "_": 10, ":": 7, "|": 15, "0a": 6]
    

    This method returns the following array:

    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
    

    Note: This order is compliant with the one used with DatasyncChildrenConstraint.

    Declaration

    Swift

    public func asArray() -> [Any]?
  • childrenKeys() Extension method

    The keys of the dictionary when this value is a JSON dictionary or [] otherwise.

    The keys are sorted using the ascending order defined by the WebcomKey type.

    For example, if this value is the following dictionary:

    ["01": 2, "1": 1, "10": 4, "2": 3, "-1": 0, "a": 11, "A": 8, "e": 12, "é": 16, "\u{20AC}": 17, "f": 13, "z": 14, "Z": 9, "-": 5, "_": 10, ":": 7, "|": 15, "0a": 6]
    

    This method returns the following array:

    ["-1", "1", "01", "2", "10", "-", "0a", ":", "A", "Z", "_", "a", "e", "f", "z", "|", "é", "€"]
    

    Declaration

    Swift

    public func childrenKeys() -> [WebcomKey]
  • decodedThrows() Extension method

    Decodes this value.

    The value is decoded from data using the jsonDecoder.

    Throws

    A WebcomError value when the decoding failed.

    Declaration

    Swift

    public func decodedThrows<T>() throws -> T where T : Decodable

    Return Value

    The decoded value.

  • decodedThrows(as:) Extension method

    Decodes this value.

    The value is decoded from data using the jsonDecoder.

    Throws

    A WebcomError value when the decoding failed.

    Declaration

    Swift

    public func decodedThrows<T>(as type: T.Type) throws -> T where T : Decodable

    Parameters

    type

    The target type for the decoding.

    Return Value

    The decoded value.

  • decoded() Extension method

    Decodes this value.

    The value is decoded from data using the jsonDecoder.

    Declaration

    Swift

    public func decoded<T>() -> T? where T : Decodable

    Return Value

    The decoded value or nil when the decoding failed.

  • decoded(as:) Extension method

    Decodes this value.

    The value is decoded from data using the jsonDecoder.

    Declaration

    Swift

    public func decoded<T>(as type: T.Type) -> T? where T : Decodable

    Parameters

    type

    The target type for the decoding.

    Return Value

    The decoded value or nil when the decoding failed.

  • serialized Extension method

    A serialized representation of this value.

    Declaration

    Swift

    public var serialized: String { get }