I have this piece of code:
struct NoteRecord: Codable {
let id: String
let title: String
let detail: String?
let dueDate: String?
private enum CodingKeys: String, CodingKey {
case id, title, detail, dueDate
}}
and parsing part:
do {
let decoder = JSONDecoder()
let note = try decoder.decode(NoteRecord.self, from: data)
} catch let err {
print("Error occured:", err)
}
Is there any way to use this when REST API returns an array of objects to decode the data correctly as array of structs?
let theNote = …line.notewill be initialised if the data is valid