Last active
February 18, 2019 22:06
-
-
Save Kdan/ca719621348836209ee66b30f0cb7d3d to your computer and use it in GitHub Desktop.
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
extension JSONDecoder { | |
/// Decode a heterogeneous list of objects. | |
/// - Parameters: | |
/// - family: The ClassFamily enum type to decode with. | |
/// - data: The data to decode. | |
/// - Returns: The list of decoded objects. | |
func decode<T: ClassFamily, U: Decodable>(family: T.Type, from data: Data) throws -> [U] { | |
return try self.decode([ClassWrapper<T, U>].self, from: data).compactMap { $0.object } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment