Array
public extension Array where Element == DataItem
extension Array: JSONPathExtractable where Element == DataItem
extension Array: DataInput where Element == DataInput
extension Array: DataInputConvertible where Element: DataInputConvertible
-
get(index:From TealiumPrismCoreas: ) Returns the data at the given index in the requested type if the conversion is possible.
Supported types are:
DoubleFloatIntInt64BoolStringNSNumber
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 followingNSNumberconversion 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:From TealiumPrismCoreconverter: ) 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) -
getDataDictionary(index:From TealiumPrismCore) -
getArray(index:From TealiumPrismCoreof: ) Returns the value at the given index as an
Arrayof the (optional) given type.This method will follow the same principles of the
get<T: DataInput>(index:as:)counterpart, but applies them on the individualArrayelements.Supported types are:
DoubleFloatIntInt64BoolStringNSNumber
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 followingNSNumberconversion 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:From TealiumPrismCoreof: ) Returns the value at the given index as an
Dictionaryof the (optional) given type.This method will follow the same principles of the
get<T: DataInput>(index:as:)counterpart, but applies them on the individualDictionaryelements.Supported types are:
DoubleFloatIntInt64BoolStringNSNumber
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 followingNSNumberconversion 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
DataItemaccording to the givenJSONArrayPath.This is equivalent to
getDataItem(index:), except it can search for nested values inside dictionaries and arrays by using aJSONArrayPath.If any component of the
JSONArrayPathis not found in this array or its nested objects and arrays, or if it is of the wrong type,nilwill 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
DataItemcontaining the string “item”.Declaration
Swift
public func extractDataItem(path: JSONArrayPath) -> DataItem?Parameters
pathThe
JSONArrayPathdescribing the path to a potentially nested item.Return Value
The required
DataItemif found; elsenil.
-
toDataInput()From TealiumPrismCoreDeclaration
Swift
public func toDataInput() -> DataInput
View on GitHub