DataObject Structure Reference
public struct DataObject : ExpressibleByDictionaryLiteral
extension DataObject: Codable
extension DataObject: DataItemExtractor
extension DataObject: DataInputConvertible
extension DataObject: CustomStringConvertible
extension DataObject: Equatable
A custom wrapper around a common Dictionary used to limit the DataInput types into the Dictionary.
Only valid DataInput types will be stored in the inner Dictionary and
only DataInputConvertible types can be used to initialize this wrapper object.
-
Declaration
Swift
public var count: Int { get }Return Value
The number of
DataItemstored in thisDataObject. -
Creates a
DataObjectfrom a list of(String, DataInputConvertible)tuple.The first element in the tuple is the key that can be used to access the item back, the second element is a convertible that will be converted immediately before being stored. In case of duplicate keys the second occurrence of the same key will replace the first one.
Declaration
Swift
public init(pairs elements: [(String, DataInputConvertible)]) -
Creates a
DataObjectfrom a[String: DataInputConvertible]dictionary literal.The Convertible elements will be converted immediately before being stored. In case of duplicate keys the second occurrence of the same key will replace the first one.
Declaration
Swift
public init(dictionaryLiteral elements: (String, DataInputConvertible)...) -
Creates a
DataObjectfrom a[String: DataInputConvertible]dictionary.The Convertible elements will be converted immediately before being stored.
Declaration
Swift
public init(dictionary: [String : DataInputConvertible] = [:]) -
Creates a DataObject from a dictionary of DataInput values.
Declaration
Swift
public init(dictionaryInput: [String : DataInput])Parameter Description dictionaryInputThe dictionary containing DataInput values.
-
Sets the value at the given key
Declaration
Swift
public mutating func set(_ value: DataInput, key: String) -
Sets the convertible value at the given key after converting it.
Declaration
Swift
public mutating func set(converting convertible: DataInputConvertible, key: String) -
Removes the value stored at the given key.
Declaration
Swift
public mutating func removeValue(forKey key: String) -
Returns the underlying dictionary of
[String: DataInput].Declaration
Swift
public func asDictionary() -> [String : DataInput] -
Sets the item in the
DataObjectby following theJSONObjectPathand recursively creating the required containers.In case the
DataObjectcontains already the nested object or array as expressed in theJSONObjectPathit will insert the new item in those objects or arrays. The missing containers will, instead, be automatically be created by this method. In case an array is not big enough to insert an item at the given index, nil items will be put until we reach the required capacity.Declaration
Swift
public mutating func buildPath(_ path: JSONObjectPath, andSet item: DataItem)Parameter Description pathThe
JSONObjectPaththat expresses the (eventually nested) location in which to put the itemitemThe item to insert at the provided location
-
Declaration
Swift
public init(from decoder: Decoder) throws -
Declaration
Swift
public func encode(to encoder: Encoder) throws -
Declaration
Swift
public func getDataItem(key: String) -> DataItem? -
Declaration
Swift
public func toDataInput() -> any DataInput -
Declaration
Swift
public var description: String { get } -
Declaration
Swift
public static func == (lhs: DataObject, rhs: DataObject) -> Bool