I have a Decodable
struct like so...
struct BestWishes: Decodable {
private enum CodingKeys : String, CodingKey {
case customerID = "customer_id"
case birthDate = "birth_date"
case type = "type"
case customerName = "customer_name"
case mobileNo = "mobile_number"
}
let customerID: Int
let date: String
let type: String
let customerName : String
let mobileNumber: Int
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
customerID = try container.decode(Int.self, forKey: .customerID)
type = try container.decode(String.self, forKey: .type)
if type == "anniversary_date" {
date = try container.decode(String.self, forKey: .anniversaryDate)
} else {
date = try container.decode(String.self, forKey: .birthDate)
}
customerName = try container.decode(String.self, forKey: .customerName)
mobileNumber = try container.decode(Int.self, forKey: .mobileNo)
}
}
And all the data within this is stored in an array like so..
var bestWishesArr = [BestWishes]()
self.bestWishesArr.append(contentsOf: result.bestWishes)
Now I would like to store bestWishesArr
to Userdefaults. Not sure how to achieve that...