Created
April 11, 2020 20:23
-
-
Save DhavalDobariya86/581b810253930d10f1206b1c80849e7f to your computer and use it in GitHub Desktop.
Codable to exclude keys by removing it from parameter list
This file contains 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
import UIKit | |
struct Country: Codable { | |
let name: String | |
let capital: String | |
} | |
let jsonData: Data = """ | |
{ | |
"name": "United States of America", | |
"capital": "Washington, D.C.", | |
"callingCodes": ["1"], | |
"region": "Americas", | |
"subregion": "Northern America", | |
"population": 323947000, | |
"area": 9629091, | |
"borders": ["CAN", "MEX"] | |
} | |
""".data(using: .utf8)! | |
let country = try! JSONDecoder().decode(Country.self, from: jsonData) | |
print("Country name = \(country.name)") | |
print("Country capital = \(country.capital)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment