mirror of
https://github.com/jphong1111/awesome-ios-developer.git
synced 2024-12-22 22:45:33 +07:00
add JSONDecoder
This commit is contained in:
parent
189c83034d
commit
3982ab5653
18
README.md
18
README.md
@ -360,6 +360,24 @@ struct User: Codable {
|
||||
}
|
||||
```
|
||||
|
||||
To use JSONDecoding, declare JSONDecoder and use decode() function
|
||||
|
||||
```swift
|
||||
do {
|
||||
let data = try JSONDecoder().decode(T.self, from: unwrappedData)
|
||||
completionOnMain(.success(data))
|
||||
} catch {
|
||||
print(error)
|
||||
completionOnMain(.failure(.parseError))
|
||||
}
|
||||
```
|
||||
|
||||
T.self -> Model(Struct) of the data that you want to decode
|
||||
> data will decoded to form of T
|
||||
|
||||
unwrappedData -> Input actual data from file or server
|
||||
> This should be a Data Type!!
|
||||
|
||||
### JSONSerialization
|
||||
|
||||
### Various API Site
|
||||
|
Loading…
Reference in New Issue
Block a user