mirror of
https://github.com/jphong1111/awesome-ios-developer.git
synced 2024-12-22 22:45:33 +07:00
edit codingkey
This commit is contained in:
parent
89af853f24
commit
e1f423f2e7
12
README.md
12
README.md
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user