Last active
March 11, 2018 07:04
-
-
Save mukulm24/ca68c8b4192df5baa88d3cab1aede561 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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