import SwiftUI
private var Username = ""
struct ContentView: View {
var body: some View {
if (UserDefaults.standard.set(self.username, forKey: "Username") != nil) {
login()
}else
{
home()
}
}
}
I am not able to get a proper answer how to store username of a log in screen in user default using swift UI. i had try giving condition to go to login screen via content viewer but i am not getting the idea to code it. can any body tell me the steps i should follow or post a sample program code so that i can refer ???????
Use @AppStorage to store and get values for user defaults.
@AppStorage("Username") var username: String = ""
or you can use also use UserDefaults.
if !UserDefaults.standard.string(forKey: "Username") {
login()
} else {
home()
}