Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
extension KeyedDecodingContainer {
func decodeIfPresent<T: Decodable>(key: K) throws -> T? {
return try decodeIfPresent(T.self, forKey: key)
func decode<T: Decodable>(key: K) throws -> T {
return try decode(T.self, forKey: key)

This comment has been minimized.

Copy link
Owner Author

gokselkoksal commented May 26, 2018

struct Person {
  let name: String


name = try container.decode(key: .name)

Instead of:

name = try container.decode(String.self, forKey: .name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.