Skip to content

Commit

Permalink
Added convenince method for parsing JSON data
Browse files Browse the repository at this point in the history
Added parsing methods that take dats objects instead of JSON strings as parameters
  • Loading branch information
ecrichlow committed May 1, 2023
1 parent 2a3b33d commit d01947e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: IoGDataObject>(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<T: IoGDataObject>(arrayString: String, forObject: T.Type) -> [T]
{
Expand All @@ -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<T: IoGDataObject>(arrayData: Data, forObject: T.Type) -> [T]
{
let contentString = String(decoding: arrayData, as: UTF8.self)
return parseArray(arrayString: contentString, forObject: forObject)
}
}

0 comments on commit d01947e

Please sign in to comment.