I would like to create a Codable structure to save data from a user profile Let's say the ios user filled a form with his name, last name,adress, put his picture (UIImage)) and that user have an unique ID . My JSON would be like
{"Unique_ID" :"1234556778",
{"Name":"John",
"Last Name" : "Doe",
"adress" :
{"street": "21 jump street",
"country" : "USA"}
}
}
I tried to create the Codable but I think it isn't optimal , could you kindly give me some hint to optimize it or tell me if I'm wrong doing it like this ?
struct User_Profile: Codable {
let Unique_ID : String
let Data_Of_User : User_Profile_Data
}
struct User_Profile_Data: Codable {
let name : String
let last_name: String
let adress : User_Adress_Data
}
struct User_Adress_Data: Codable {
let street : String
let country: String
}
override func viewDidLoad() {
super.viewDidLoad()
let usernametest = "John"
let b = User_Adress_Data(street: "21 jump street", country: "USA")
let c = User_Profile_Data(name: usernametest, last_name: "Doe", adress: b)
let d = User_Profile(Unique_ID: "123456", Data_Of_User: c)
}
After that, I would like to cache it, with Haneke swift(https://github.com/Haneke/HanekeSwift), or Datacache (https://github.com/huynguyencong/DataCache) How can I cache my Codables? (for eg, I didn't view any 'set cache for json' with Haneke)
And finally, I would like to use it after fetched with SwiftyJSON : (https://github.com/SwiftyJSON/SwiftyJSON), and I don't know if my Codables are enought readable for it.
Thanks for your idea/comment !