Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ankit-slnk/ios_swiftui_pagination_api_call
iOS SwiftUI Pagination & Api Call Demo
https://github.com/ankit-slnk/ios_swiftui_pagination_api_call
api demo ios ios-swiftui-pagination pagination swiftui
Last synced: about 1 month ago
JSON representation
iOS SwiftUI Pagination & Api Call Demo
- Host: GitHub
- URL: https://github.com/ankit-slnk/ios_swiftui_pagination_api_call
- Owner: Ankit-Slnk
- Created: 2020-11-25T11:13:36.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-15T08:46:11.000Z (over 3 years ago)
- Last Synced: 2024-03-10T18:35:16.565Z (10 months ago)
- Topics: api, demo, ios, ios-swiftui-pagination, pagination, swiftui
- Language: Swift
- Homepage: https://ankitsolanki.dev
- Size: 287 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# iOS SwiftUI Pagination & Api Call Demo
![Flutter Pagination & Api Call Demo](ios_swiftui_pagination_api_call.png)
This demo will show us how to call `post` and `get` HTTP request in iOS swiftUI. This will also show us how to use `pagination` in list.
## Setup
Use latest versions of below mentioned pods in `Podfile`.
| Pod | Explanation |
|-----|-------------|
| [Alamofire](https://github.com/Alamofire/Alamofire) | Alamofire is an HTTP networking library written in Swift. |
| [URLImage](https://github.com/dmytro-anokhin/url-image) | URLImage is a SwiftUI view that displays an image downloaded from provided URL. |### Check internet connectivity
import Foundation
import Alamofireclass Reachability {
static let sharedInstance = NetworkReachabilityManager()!
static var isConnectedToInternet:Bool {
return self.sharedInstance.isReachable
}
}### GET Request
GET https://reqres.in/api/users?page=
Convert `JSON` response from this api to `swift class` using [quicktype](https://app.quicktype.io).
if Reachability.isConnectedToInternet {
let parameters: [String: String] = [
"page": page.description,
]
let headers: HTTPHeaders = [
"Accept": "application/json"
]
let request = AF.request(AppStrings.USERS,
method: .get,
parameters: parameters,
//encoding: JSONEncoding.default, // comment this if need paramenter for get call
headers: headers)
request.responseDecodable(of: UsersResponse.self) { (response) in
print(response.debugDescription)
guard let apiResponse = response.value else { return }
if apiResponse.data.count > 0 {
self.userDetails.append(contentsOf: apiResponse.data)
self.page += 1
}
self.stopLoading = (apiResponse.total == self.userDetails.count)
}
} else {
toastMessage = AppStrings.noInternet
isShowToast.toggle()
}### Show list of users in SwiftUI
NavigationView {
List {
ForEach(0..