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
struct Apartment : Codable { | |
var buildingName : String | |
var rent : Float | |
var address : Address | |
} |
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
struct Address : Codable { | |
var flatNumber : Int | |
var streetName : String | |
var city : String | |
var state : String | |
var country : String | |
} |
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
func createAppartmentToRent(){ | |
let oxfordAptAddress = Address(flatNumber: 24, streetName: "Elphinston Road", city: "Pune", state: "Maharashtra", country: "India") | |
let oxfordApt = Apartment(buildingName: "Oxford", rent: 18500.0, address: oxfordAptAddress) | |
} |
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){ |
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
func getAptJSON() -> String { | |
let bravuriaAptJSON = "{\"address\":{\"state\":\"UP\",\"flatNumber\":24,\"city\":\"Kanpur\",\"streetName\":\"MH Area\",\"country\":\"India\"},\"buildingName\":\"Bravuria\",\"rent\":18500}" | |
return bravuriaAptJSON | |
} |
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
/** | |
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) { |