Skip to content

Instantly share code, notes, and snippets.

@toddkramer
Created July 23, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddkramer/63322225d08e75e06db5463c19f11363 to your computer and use it in GitHub Desktop.
Save toddkramer/63322225d08e75e06db5463c19f11363 to your computer and use it in GitHub Desktop.
Annotation (Single Value Container)
struct Annotation: Decodable {
let drawings: [Drawing]
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let string = try container.decode(String.self)
guard let data = string.data(using: .utf8) else {
let context = DecodingError.Context(codingPath: [], debugDescription: "Annotation data could not be serialized.")
throw DecodingError.dataCorrupted(context)
}
self.drawings = try JSONDecoder().decode([Drawing].self, from: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment