You may encounter a scenario where you want to decode some JSON that contains an array of objects that may be of a different type. In this episode we examine such a scenario, where we have a feed that contains an array of posts, but each post object can be of a different kind, such as text, image, or video. We will take a look at how to solve this by introducing a protocol called DecodableClassFamily, and along with a Discriminator that will inform the decoding logic which type it should decode. We'll then take this working example and make a reusable solution using Swift Generics.
This is a companion discussion topic for the original entry at https://nsscreencast.com/episodes/395-decoding-heterogeneous-arrays