My model class:
struct AllRestroVendor:Codable{
let vendorID, name: String?
let rating: Rating?
let option: [Options]?
enum CodingKeys: String, CodingKey {
case vendorID = "vendor_id"
case name
case rating
case options
}}
struct Rating: Codable {
let count, rating, image, name: String?
}
struct Options: Codable{
let name, price: String?
}
I am trying to store this model data in userdefaults.
func setWishList(details :AllRestroVendor) {
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(details) {
let defaults = UserDefaults.standard
defaults.set(encoded, forKey: UD_WISHLIST)
}
userdefaultsSynchronize()
}
func getWishList() -> AllRestroVendor {
let defaults = UserDefaults.standard
if let topicsList = defaults.object(forKey: "topic_list") as? Data {
let decoder = JSONDecoder()
if let loadedList = try? decoder.decode(AllRestroVendor.self, from: topicsList) {
return loadedList
}
}
let aData = AllRestroVendor(vendorID: "", name: "", rating: Rating?, options: [])
return aData
}
Here getting an error "Cannot convert value of type 'Rating?.Type' to expected argument type 'Rating?'"
I gothrough every anyswers. But unfortunately cannot resolve this issue. Help me to solve this.