Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created December 21, 2020 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/63c8900adead1ed19d0f2b645fbc07e4 to your computer and use it in GitHub Desktop.
Save sturdysturge/63c8900adead1ed19d0f2b645fbc07e4 to your computer and use it in GitHub Desktop.
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