WebcomValuable
public protocol WebcomValuable
A type to represent a JSON value.
-
The value as binary data.
Declaration
Swift
var data: Data? { get } -
The value as JSON.
Declaration
Swift
var json: Any? { get } -
The JSON decoder to decode this value.
This decoder is used by the
decoded(),decoded(as:),decodedThrows()anddecodedThrows(as:)methods.Declaration
Swift
var jsonDecoder: JSONDecoder { get }
-
isNullExtension methodIndicates whether this value is
null(not to be confused with the Swiftnilkeyword).Declaration
Swift
public var isNull: Bool { get } -
asStringExtension methodThis value as a string, or
nilwhen this value is not a string.Declaration
Swift
public var asString: String? { get } -
asKeyExtension method -
asBoolExtension methodThis value as a boolean, or
falsewhen this value is not a boolean.Declaration
Swift
public var asBool: Bool { get } -
asBool(default:Extension method) Returns this value as a boolean, or
defaultValuewhen this is value is not a boolean.Declaration
Swift
public func asBool(default defaultValue: Bool) -> BoolParameters
defaultValueThe value to return when this value is not a boolean.
-
asIntExtension methodThis value as an integer, or
nilwhen this is value is not an integer.Declaration
Swift
public var asInt: Int? { get } -
asDoubleExtension methodThis value as a double-precision floating-point number, or
nilwhen this is value is not a floating-point number.Declaration
Swift
public var asDouble: Double? { get } -
asDictionary()Extension methodThis value as a JSON dictionary, or
nilwhen this value is not a JSON dictionary.Declaration
Swift
public func asDictionary() -> [WebcomKey : Any]? -
asArray()Extension methodThis value as an array, or
nilwhen 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"…).When this value is stored as a dictionary, whether it was set as an array or as a dictionary with any keys, this method returns an array by:
- sorting the keys using the ascending order defined by the
WebcomKeytype, - removing the keys to keep only the values of the children.
Otherwise, this property is
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]? - sorting the keys using the ascending order defined by the
-
childrenKeys()Extension methodThe keys of the dictionary when this value is a JSON dictionary, or
[]otherwise.The keys are sorted using the ascending order defined by the
WebcomKeytype.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", "|", "é", "€"]Since
2.2.0Declaration
Swift
public func childrenKeys() -> [WebcomKey] -
keys()Extension methodThe keys of the dictionary when this value is a JSON dictionary, or
[]otherwise.Warning
This method was deprecated in version 2.2.0. UsechildrenKeys()instead.Declaration
Swift
@available(*, deprecated, renamed: "childrenKeys(﹚") public func keys() -> [WebcomKey] -
decodedThrows()Extension methodDecodes this value.
The value is decoded from
datausing thejsonDecoder.Throws
AWebcomErrorvalue when the decoding failed.Declaration
Swift
public func decodedThrows<T>() throws -> T where T : DecodableReturn Value
The decoded value.
-
decodedThrows(as:Extension method) Decodes this value.
The value is decoded from
datausing thejsonDecoder.Throws
AWebcomErrorvalue when the decoding failed.Declaration
Swift
public func decodedThrows<T>(as type: T.Type) throws -> T where T : DecodableParameters
typeThe target type for the decoding.
Return Value
The decoded value.
-
decoded()Extension methodDecodes this value.
The value is decoded from
datausing thejsonDecoder.Declaration
Swift
public func decoded<T>() -> T? where T : DecodableReturn Value
The decoded value or
nilwhen the decoding failed. -
decoded(as:Extension method) Decodes this value.
The value is decoded from
datausing thejsonDecoder.Declaration
Swift
public func decoded<T>(as type: T.Type) -> T? where T : DecodableParameters
typeThe target type for the decoding.
Return Value
The decoded value or
nilwhen the decoding failed. -
serializedExtension methodA serialized representation of this value.
Declaration
Swift
public var serialized: String { get }