This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
typealias CompletionHandler = (Data) -> Void | |
typealias FailureHandler = (APIError) -> Void | |
struct EmptyRequest: Encodable {} // Added this | |
struct EmptyResponse: Decodable {} // Added this | |
enum HTTPMethod: String { | |
case get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
typealias CompletionHandler = (Data) -> Void | |
typealias FailureHandler = (APIError) -> Void | |
struct EmptyRequest: Encodable {} // Added this | |
struct EmptyResponse: Decodable {} // Added this | |
enum HTTPMethod: String { | |
case get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if viewModel.error == .noInternet { | |
Text("No internet") | |
.fontWeight(.bold) | |
.foregroundColor(.red) | |
} else if viewModel.error != nil { | |
Text("Login error") | |
.fontWeight(.bold) | |
.foregroundColor(.red) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
static func call( | |
scheme: String = Config.shared.scheme, | |
host: String = Config.shared.host, | |
path: String, | |
method: HTTPMethod, | |
parameters: Parameters? = nil, | |
completion: @escaping CompletionHandler, | |
failure: @escaping FailureHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum APIError: String, Error { | |
case jsonDecoding | |
case response | |
case noInternet // Added this | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
@main | |
struct SwiftUIBlueprintApp: App { | |
init() { | |
NetworkMonitor.shared.startMonitoring() // Added this | |
} | |
var body: some Scene { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Network | |
class NetworkMonitor { | |
static let shared: NetworkMonitor = NetworkMonitor() | |
let monitor = NWPathMonitor() | |
private var status: NWPath.Status = .requiresConnection | |
var isReachable: Bool { status == .satisfied } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct LoginScreen: View { | |
@ObservedObject var viewModel: LoginViewModel = LoginViewModel() | |
var body: some View { | |
VStack { | |
Spacer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class LoginViewModel: ObservableObject { | |
@Published var username: String = "" | |
@Published var password: String = "" | |
@Published var error: APIError? // Added this | |
func login() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct LoginAction { | |
let path = "/login" | |
let method: HTTPMethod = .post | |
var parameters: LoginRequest | |
func call( | |
completion: @escaping (LoginResponse) -> Void, | |
failure: @escaping (APIError) -> Void // Added this |
NewerOlder