Created
July 23, 2018 19:08
-
-
Save toddkramer/63322225d08e75e06db5463c19f11363 to your computer and use it in GitHub Desktop.
Annotation (Single Value Container)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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