Skip to content

Instantly share code, notes, and snippets.

View marinbenc's full-sized avatar

Marin Benčević marinbenc

View GitHub Profile
@iKova47
iKova47 / Array+Decodable.swift
Last active January 24, 2017 10:30 — forked from marinbenc/Array+Decodable.swift
Make a Swift Array conform to Decodable (for JSON parsing)
/*
*
* An extension for array that takes JSON as a parameter and tries to parse all elements form the given
* JSON to the Decodable.Type model. Also, in case that the given JSON is not an array type, it will try
* to parse single model and append it to the self.
*
* Useful in situations where JSON sometimes can be object and some other times array, e.g. when converting from XML to JSON.
*
* This extension uses SwiftyJSON as JSON parsing engine, but it can be made to work with other libraries or manual parsing from Dictionary json.
*/