Skip to content

Instantly share code, notes, and snippets.

// Post
func fetchToken(reqBody: TokenRequest) -> AnyPublisher<TokenResponse, AFError> {
let url = URL(string: baseURL + Endpoints.start.makeURL)!
let headers: HTTPHeaders = [
"Content-Type" : "application/json"
]
return AF.request(url, method: .post, parameters: reqBody, encoder: JSONParameterEncoder.default, headers: headers)
.validate()
@LukaszDziwosz
LukaszDziwosz / ContentView.swift
Created August 8, 2022 16:38
GitHub search with SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
SearchRepoViewDI().searchRepoView
}
}
@LukaszDziwosz
LukaszDziwosz / ErrorView.swift
Created August 8, 2022 16:17
GitHub search with Alamofire
import SwiftUI
enum ErrorType {
case decoding
case noInternet
case backend(Int)
}
struct ErrorView: View {
@LukaszDziwosz
LukaszDziwosz / SearchRepoView.swift
Created August 8, 2022 16:15
GitHubSearch with Alamofire
import SwiftUI
struct SearchRepoView: View {
@ObservedObject var viewModel: SearchRepoViewModel
var body: some View {
NavigationView {
VStack {
switch viewModel.state {
@LukaszDziwosz
LukaszDziwosz / SearchRepoViewModel.swift
Created August 8, 2022 15:52
GitHub search with Alamofire
import Foundation
import Combine
final class SearchRepoViewModel: ObservableObject {
// MARK: - Published properties
@Published var searchQuery = ""
@Published private(set) var state = PageState.idle
@LukaszDziwosz
LukaszDziwosz / RepoAPI.swift
Last active August 8, 2022 15:03
GitHub Search Alamofire
import Foundation
import Combine
import Alamofire
protocol RepoAPIProtocol {
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError>
}
struct RepoAPI: RepoAPIProtocol {
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError> {