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"

}

}

}

}


要查看或添加评论,请登录

pravin parmar的更多文章

  • SwiftUI AppStorage

    SwiftUI AppStorage

    What is AppStorage ? @AppStorage has property wrappers designed to store data persistently. it has for user preferences…

社区洞察

其他会员也浏览了