Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created February 6, 2020 20:14
Show Gist options
  • Save BetterProgramming/3f1bb8b940c5ca7e222ac64e60008495 to your computer and use it in GitHub Desktop.
Save BetterProgramming/3f1bb8b940c5ca7e222ac64e60008495 to your computer and use it in GitHub Desktop.
extension Decoder {
func getContext(forKey key: String) -> Any? {
let infoKey = CodingUserInfoKey(rawValue: key)!
return userInfo[infoKey]
}
}
extension JSONDecoder {
func set(context: Any?, forKey key: String) {
let infoKey = CodingUserInfoKey(rawValue: key)!
userInfo[infoKey] = context
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment