Skip to content

Instantly share code, notes, and snippets.

@toddkramer
Created July 23, 2018 19:11
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/8b6df9048a2a368d43f0eefaa0342442 to your computer and use it in GitHub Desktop.
Save toddkramer/8b6df9048a2a368d43f0eefaa0342442 to your computer and use it in GitHub Desktop.
Comment Model (Lazy Decoding)
class Comment: Decodable {
let id: String
let text: String
let frame: Int
let annotation: String?
private(set) lazy var drawings: [Drawing]? = {
guard let annotationData = annotation?.data(using: .utf8) else { return nil }
return try? JSONDecoder().decode([Drawing].self, from: annotationData)
}()
init(id: String, text: String, frame: Int, annotation: String?) {
self.id = id
self.text = text
self.frame = frame
self.annotation = annotation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment