DataObject

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 keys: Dictionary<String, any DataInput>.Keys { get }

    Return Value

    The keys of the DataItem stored in this DataObject.

  • Declaration

    Swift

    public var count: Int { get }

    Return Value

    The number of DataItem stored in this DataObject.

  • Creates a DataObject from 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 DataObject from 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 DataObject from 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])

    Parameters

    dictionaryInput

    The 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 DataObject by following the JSONObjectPath and recursively creating the required containers.

    In case the DataObject contains already the nested object or array as expressed in the JSONObjectPath it 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)

    Parameters

    path

    The JSONObjectPath that expresses the (eventually nested) location in which to put the item

    item

    The 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