Skip to content

Instantly share code, notes, and snippets.

@mukulm24
Created March 11, 2018 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mukulm24/e4920c37b86b87af7b95a25f6e4e93f8 to your computer and use it in GitHub Desktop.
Save mukulm24/e4920c37b86b87af7b95a25f6e4e93f8 to your computer and use it in GitHub Desktop.
/**
Converts a JSON String to it's corresponding object
params : aptJSON -> The JSON string which needs to be decoded
returns: Apartment object keeping JSON string as Datasource
*/
func decodingJSONToApartment(aptJSON : String) -> Apartment?{
print("\n\nDECODING DATA")
if let aptJsonData = aptJSON.data(using: .utf8) {
let decoder = JSONDecoder()
if let oxfordApt = try? decoder.decode(Apartment.self, from: aptJsonData) {
print(oxfordApt)
return oxfordApt
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment