Skip to content

Instantly share code, notes, and snippets.

@mukulm24
Last active March 11, 2018 07:04
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/ca68c8b4192df5baa88d3cab1aede561 to your computer and use it in GitHub Desktop.
Save mukulm24/ca68c8b4192df5baa88d3cab1aede561 to your computer and use it in GitHub Desktop.
/**
To convert an apartment object to JSON string.
returns : JSON string for the respective apartment object
*/
func convertToJSON(apartmentInfo: Apartment) -> String?{
let encoder = JSONEncoder()
if let encodedApt = try? encoder.encode(apartmentInfo){
//If you wish to use the data instead of JSON string, you can go ahead and use encodedApt which is JSON encoded data.
if let jsonApt = String(data: encodedApt, encoding: .utf8) {
print(jsonApt)
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment