Array

From TealiumPrismCore:
public extension Array where Element == DataItem
extension Array: JSONPathExtractable where Element == DataItem
extension Array: DataInput where Element == DataInput
extension Array: DataInputConvertible where Element: DataInputConvertible

Available where Element == DataItem

  • get(index:as:) From TealiumPrismCore

    Returns the data at the given index in the requested type if the conversion is possible.

    Supported types are:

    • Double
    • Float
    • Int
    • Int64
    • Bool
    • String
    • NSNumber

    You can call this method without parameters if the return type can be inferred:

     let dataItems: [DataItem] = [DataItem(value: 1.5)]
     let anInt: Int? = dataItems.get(index: 0)
    

    Alternatively the type must be specified as a parameter:

     let dataItems: [DataItem] = [DataItem(value: 1.5)]
     let anInt = dataItems.get(index: 0, as: Int.self)
    

    Every numeric type (Int, Int64, Float, Double, NSNumber) can be used interchangeably and the conversion will be made following NSNumber conversion methods.

     let nsNumber = NSNumber(1.5)
     let dataItems: [DataItem] = [DataItem(value: nsNumber)]
     let aDouble: Double? = dataItems.get(index: 0) // Double(1.5)
     let anInt: Int? = dataItems.get(index: 0) // Int(1)
    

    Declaration

    Swift

    func get<T>(index: Index, as type: T.Type = T.self) -> T? where T : DataInput
  • getConvertible(index:converter:) From TealiumPrismCore

    Declaration

    Swift

    func getConvertible<T>(index: Index, converter: any DataItemConverter<T>) -> T?

    Return Value

    The value at the given index after having been converted by the DataItemConverter.

  • getDataArray(index:) From TealiumPrismCore

    Returns the value as an Array of DataItem if the underlying value is an Array.

    Warning

    Do not cast the return object as any cast will likely fail. Use the appropriate methods to extract value from a DataItem.

    Declaration

    Swift

    func getDataArray(index: Index) -> [DataItem]?
  • getDataDictionary(index:) From TealiumPrismCore

    Returns the value as a Dictionary of DataItem if the underlying value is a Dictionary.

    Warning

    Do not cast the return object as any cast will likely fail. Use the appropriate methods to extract value from a DataItem.

    Declaration

    Swift

    func getDataDictionary(index: Index) -> [String : DataItem]?
  • getArray(index:of:) From TealiumPrismCore

    Returns the value at the given index as an Array of the (optional) given type.

    This method will follow the same principles of the get<T: DataInput>(index:as:) counterpart, but applies them on the individual Array elements.

    Supported types are:

    • Double
    • Float
    • Int
    • Int64
    • Bool
    • String
    • NSNumber

    You can call this method without parameters if the return type can be inferred:

     let dataItems: [DataItem] = [DataItem(value: 1.5)]
     let anIntArray: [Int?]? = dataItems.getArray(index: 0)
    

    Alternatively the type must be specified as a parameter:

     let dataItems: [DataItem] = [DataItem(value: 1.5)]
     let anIntArray = dataItems.getArray(index: 0, of: Int.self)
    

    Every numeric type (Int, Int64, Float, Double, NSNumber) can be used interchangeably and the conversion will be made following NSNumber conversion methods.

     let nsNumber = NSNumber(1.5)
     let dataItems: [DataItem] = [DataItem(value: nsNumber)]
     let aDoubleArray = dataItems.getArray(index: 0, of: Double.self) // [Double(1.5)]
     let anIntArray = dataItems.getArray(index: 0, of: Int.self) // [Int(1)]
    

    Declaration

    Swift

    func getArray<T>(index: Index, of type: T.Type = T.self) -> [T?]? where T : DataInput
  • getDictionary(index:of:) From TealiumPrismCore

    Returns the value at the given index as an Dictionary of the (optional) given type.

    This method will follow the same principles of the get<T: DataInput>(index:as:) counterpart, but applies them on the individual Dictionary elements.

    Supported types are:

    • Double
    • Float
    • Int
    • Int64
    • Bool
    • String
    • NSNumber

    You can call this method without parameters if the return type can be inferred:

     let dataItems: [DataItem] = [DataItem(value: 1.5)]
     let anIntDictionary: [String: Int?]? = dataItems.getDictionary(index: 0)
    

    Alternatively the type must be specified as a parameter:

     let dataItems: [DataItem] = [DataItem(value: 1.5)]
     let anIntDictionary = dataItems.getDictionary(index: 0, of: Int.self)
    

    Every numeric type (Int, Int64, Float, Double, NSNumber) can be used interchangeably and the conversion will be made following NSNumber conversion methods.

     let nsNumber = NSNumber(1.5)
     let dataItems: [DataItem] = [DataItem(value: nsNumber)]
     let aDoubleDictionary = dataItems.getDictionary(index: 0, of: Double.self) // ["someKey": Double(1.5)]
     let anIntDictionary = dataItems.getDictionary(index: 0, of: Int.self) // ["someKey": Int(1)]
    

    Declaration

    Swift

    func getDictionary<T>(index: Index, of type: T.Type = T.self) -> [String : T?]? where T : DataInput
  • extractDataItem(path:) From TealiumPrismCore

    Extracts a nested DataItem according to the given JSONArrayPath.

    This is equivalent to getDataItem(index:), except it can search for nested values inside dictionaries and arrays by using a JSONArrayPath.

    If any component of the JSONArrayPath is not found in this array or its nested objects and arrays, or if it is of the wrong type, nil will be returned.

    As an example, in the following snippet:

     let array = [
         DataItem(converting: [
           "property": [
              "item"
           ]
         ])
     ])
     let result = array.extractDataItem(path: JSONPath[0]["property"][0])
    

    The result would be a DataItem containing the string “item”.

    Declaration

    Swift

    public func extractDataItem(path: JSONArrayPath) -> DataItem?

    Parameters

    path

    The JSONArrayPath describing the path to a potentially nested item.

    Return Value

    The required DataItem if found; else nil.

Available where Element: DataInputConvertible