Skip to content

Instantly share code, notes, and snippets.

@mzumi
Last active February 27, 2017 03:42
Show Gist options
  • Save mzumi/5daf87b758f1c10a849d67167b4f4c67 to your computer and use it in GitHub Desktop.
Save mzumi/5daf87b758f1c10a849d67167b4f4c67 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
}
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