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
<key>LSApplicationQueriesSchemes</key> | |
<array> | |
<string>instagram-stories</string> | |
</array> |
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
struct User: Codable { | |
let name: String | |
let color: Color | |
enum Color: String, Codable { | |
case red = "RED" | |
case yelllow = "YELLOW" | |
case blue = "BLUE" | |
} | |
} |
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
// This data contains the following JSON data | |
// { | |
// "name": "Mario", | |
// "color": "YELLOW" | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) |
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
// { | |
// "name": "Janine", | |
// "color": "GREEN" | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) | |
print(object) // nil |
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
// { | |
// "name": "Kermaine", | |
// "color": "RED", | |
// "number": 14 | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) |
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
struct User: Codable { | |
let name: String | |
let color: Color? | |
enum Color: String, Codable { | |
case red = "RED" | |
case yelllow = "YELLOW" | |
case blue = "BLUE" | |
} | |
} |
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
struct User: Codable { | |
let name: String | |
let preferences: [Preference] | |
} | |
struct Account: Codable { | |
let uuid: String | |
let email: String? | |
let address: Address? | |
} |
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
protocol UnknownCase: RawRepresentable, CaseIterable where RawValue: Equatable & Encodable { | |
static var unknownCase: Self { get } | |
} | |
extension UnknownCase { | |
init(rawValue: RawValue) { | |
let value = Self.allCases.first { $0.rawValue == rawValue } | |
self = value ?? Self.unknownCase | |
} |
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
struct User: Codable { | |
let name: String | |
let color: Color | |
enum Color: String, Codable, UnknownCase { | |
static let unknwonCase: Self = .unknown | |
case red = "RED" | |
case yelllow = "YELLOW" | |
case blue = "BLUE" |
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
// { | |
// "name": "Janine", | |
// "color": "GREEN" | |
// } | |
let data = requestData() | |
let decoder = JSONDecoder() | |
let object = try? decoder.decode(User.self, from: data) | |
print(object) // User(name: "Janine", color: .unknown) |