From d01947ee7ead1876f5ce1b4c25e49368ced03ae5 Mon Sep 17 00:00:00 2001 From: Eric Crichlow Date: Mon, 1 May 2023 13:01:23 -0700 Subject: [PATCH] Added convenince method for parsing JSON data Added parsing methods that take dats objects instead of JSON strings as parameters --- .../Data Parsing/IoGDataObjectManager.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Source/IoGInfrastructure/Managers/Data Parsing/IoGDataObjectManager.swift b/Source/IoGInfrastructure/Managers/Data Parsing/IoGDataObjectManager.swift index af1a1e8..f790717 100644 --- a/Source/IoGInfrastructure/Managers/Data Parsing/IoGDataObjectManager.swift +++ b/Source/IoGInfrastructure/Managers/Data Parsing/IoGDataObjectManager.swift @@ -33,6 +33,13 @@ public class IoGDataObjectManager return T.init(withString: objectString) } + /// Parses Data object containing JSON string for a single JSON object and returns an instance of the provided type, which must be a subclass of IoGDataObject + public func parseObject(objectData: Data, toObject: T.Type) -> T + { + let contentString = String(decoding: objectData, as: UTF8.self) + return parseObject(objectString: contentString, toObject: toObject) + } + /// Parses JSON string for an array of JSON objects and returns an array of the provided type, which must be a subclass of IoGDataObject public func parseArray(arrayString: String, forObject: T.Type) -> [T] { @@ -59,4 +66,11 @@ public class IoGDataObjectManager return objectArray } + + /// Parses Data object containing JSON string for an array of JSON objects and returns an array of the provided type, which must be a subclass of IoGDataObject + public func parseArray(arrayData: Data, forObject: T.Type) -> [T] + { + let contentString = String(decoding: arrayData, as: UTF8.self) + return parseArray(arrayString: contentString, forObject: forObject) + } }