Skip to content

Instantly share code, notes, and snippets.

@Qata
Created April 6, 2016 08:51
Show Gist options
  • Save Qata/16484878d51301210c85f512fd05dbb2 to your computer and use it in GitHub Desktop.
Save Qata/16484878d51301210c85f512fd05dbb2 to your computer and use it in GitHub Desktop.
extension Decodable {
static func oneOf(json: AnyObject, objects: (Decodable.Type)...) throws -> Decodable {
for decodable in objects.dropLast() {
if let decoded = try? decodable.decode(json) {
return decoded
}
}
return try (objects.last!).decode(json)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment