SwiftUI AppStoage
What is AppStorage ?
@AppStorage has property wrappers designed to store data persistently. it has for user preferences are shared across the app.
Example
import SwiftUI
struct ContentView: View {
// Define a property using @AppStorage
storage app("username") var username: String = "iPhone15"
var body: some View {
VStack {
Text("ios developer, \(username)!")
Button("Change Username") {
// Update the value stored in UserDefaults
username = "iPhone16"
}
}
}
}