I am currently struggling to figure out where to correctly place the .register() method to set an initial/default value for UserDefaults (on every launch of the app).
Here is where I tried to initialize it in the "App" file that Xcode generated with the project:
import SwiftUI
@main
struct TestApp: App {
init() {
//Sets default values for the user defaults that have not yet been set and should not return 0/false
UserDefaults.standard.register(defaults: [
"selectedRoundLength": 1
]
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
However, this doesn't really seem to do the trick. Does anyone have input on this one?