Skip to content

Instantly share code, notes, and snippets.

View DhavalDobariya86's full-sized avatar

Dhaval Dobariya DhavalDobariya86

View GitHub Profile
@DhavalDobariya86
DhavalDobariya86 / Codable+ExcludeKeys+CodingKeys.swift
Created April 11, 2020 20:25
Codable to exclude keys by removing it from CodingKeys enum
import UIKit
struct Country: Codable {
let name: String
let capital: String
let alternateSpellings: [String]
enum CodingKeys: String, CodingKey {
case name
case capital
@DhavalDobariya86
DhavalDobariya86 / Codable+ExcludeKeys.swift
Created April 11, 2020 20:23
Codable to exclude keys by removing it from parameter list
import UIKit
struct Country: Codable {
let name: String
let capital: String
}
let jsonData: Data = """
{
"name": "United States of America",
@DhavalDobariya86
DhavalDobariya86 / Codable+DateDecodingStrategy.swift
Created April 11, 2020 20:20
Codable with Date decoding strategy
import UIKit
struct Country: Codable {
let name: String
let capital: String
let independanceDay: Date
}
let jsonData: Data = """
{
@DhavalDobariya86
DhavalDobariya86 / Codable+KeyDecodingStrategy.swift
Created April 11, 2020 20:18
Codable with Key decoding strategy
import UIKit
struct Country: Codable {
let name: String
let capital: String
let callingCodes: [String]
}
let jsonData: Data = """
{
@DhavalDobariya86
DhavalDobariya86 / Codable+RenamedParameters.swift
Last active April 11, 2020 20:16
Codable with renamed parameters
import UIKit
struct Country: Codable {
let name: String
let capital: String
let alternateSpellings: [String]
enum CodingKeys: String, CodingKey {
case name
case capital
@DhavalDobariya86
DhavalDobariya86 / Codable.swift
Last active April 11, 2020 20:12
Simple use of Codable to encode/decode JSON
import UIKit
struct Country: Codable {
let name: String
let capital: String
let callingCodes: [String]
let population: Double
let area: Double
let borders: [String]
let region: String