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 }
-
isNull
Extension methodIndicates whether this value is
null
(not to be confused with the Swiftnil
keyword).Declaration
Swift
public var isNull: Bool { get }
-
asString
Extension methodThis value as a string, or
nil
when this value is not a string.Declaration
Swift
public var asString: String? { get }
-
asKey
Extension method -
asBool
Extension methodThis 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 is 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 methodThis value as an integer, or
nil
when this is value is not an integer.Declaration
Swift
public var asInt: Int? { get }
-
asDouble
Extension methodThis value as a double-precision floating-point number, or
nil
when 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
nil
when this value is not a JSON dictionary.Declaration
Swift
public func asDictionary() -> [WebcomKey : Any]?
-
asArray()
Extension methodThis 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"
…).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
WebcomKey
type, - 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
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", "|", "é", "€"]
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
data
using thejsonDecoder
.Throws
AWebcomError
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 thejsonDecoder
.Throws
AWebcomError
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 methodDecodes this value.
The value is decoded from
data
using thejsonDecoder
.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 thejsonDecoder
.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 methodA serialized representation of this value.
Declaration
Swift
public var serialized: String { get }