Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
StaticStringConstants
import SwiftUI
extension String {
static let nameKey = "nameKey"
static let ageKey = "ageKey"
}
struct ContentView: View {
@AppStorage(.nameKey) var name: String = ""
let age = UserDefaults.standard.integer(forKey: .ageKey)
var body: some View {
VStack {
Text("name: \(name)")
Text("age: \(age)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment