Posts

Post not yet marked as solved
5 Replies
How then would you recommend initializing an object from decoder that has say two different variations depending on where you are deserializing it from. For ExampleLets say I get the first book from http://library.com/bookLocations/{id}And the second book from http://library.com/bookInfo/{id}Book: { Author: "James" Title: "JamesBook" LibraryId: "387fh384fh3i09" SectionNumber: "870D" }Book: { Author: "James" Title: "JamesBook" Length: "870" Reviews: "9/10" }What is the best way to handle both cases insideinit(from decoder: Decoder)if I want to use the same model/object for bothstruct Book: Codable { var author: String var title: String var libraryId: String? var sectionNumber: String? var length: String? var reviews: String? }