Skip to content

Instantly share code, notes, and snippets.

@mzumi
Created February 27, 2017 03:32
Show Gist options
  • Save mzumi/39d252a668fff497c9795ad532f31e41 to your computer and use it in GitHub Desktop.
Save mzumi/39d252a668fff497c9795ad532f31e41 to your computer and use it in GitHub Desktop.
extension Dictionary where Key : ExpressibleByStringLiteral {
func extractValue<T>(key: String) throws -> T {
let keyStr = key as! Key
if let r = self[keyStr] as? T {
return r
} else {
throw JSONDecodeError.missingValue(key: key, actualValue: self[keyStr])
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment