Skip to content

Instantly share code, notes, and snippets.

@karenxpn
Created December 5, 2021 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenxpn/4c989a6ac014449d26c53febb7394020 to your computer and use it in GitHub Desktop.
Save karenxpn/4c989a6ac014449d26c53febb7394020 to your computer and use it in GitHub Desktop.
Alert View Model Log Out example
import Foundation
import SwiftUI
class AlertViewModel {
@AppStorage("token") private var token: String = ""
func makeAlert(with error: NetworkError, message: inout String, alert: inout Bool ) {
if error.initialError.responseCode == 401 {
self.token = ""
} else {
message = error.backendError == nil ? error.initialError.localizedDescription : error.backendError!.message
alert.toggle()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment