Created
December 5, 2021 02:20
-
-
Save karenxpn/4c989a6ac014449d26c53febb7394020 to your computer and use it in GitHub Desktop.
Alert View Model Log Out example
This file contains hidden or 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 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