Created
April 6, 2016 08:51
-
-
Save Qata/16484878d51301210c85f512fd05dbb2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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