edit codingkey

This commit is contained in:
Jungpyo Hong 2021-05-27 11:28:20 -05:00 committed by GitHub
parent 89af853f24
commit e1f423f2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -443,11 +443,19 @@ public typealias Codable = Decodable & Encodable
```swift
struct User: Codable {
var first_name: String
var last_name: String
var firstName: String
var lastName: String
var country: String
enum CodingKeys: String, CodingKey {
case firstName = "first_name"
case lastName = "last_name"
case country
}
}
```
> To avoid snake_case in swift, use CodingKeys or JSONDecoder.KeyDecodingStrategy
To use JSONDecoding, declare JSONDecoder and use decode() function