Skip to content

Instantly share code, notes, and snippets.

@mdb1
Created May 6, 2023 13:50
Show Gist options
  • Save mdb1/6dc6f55a87dd5a2417d8a3fe7aaec134 to your computer and use it in GitHub Desktop.
Save mdb1/6dc6f55a87dd5a2417d8a3fe7aaec134 to your computer and use it in GitHub Desktop.
A SwiftUI view to pick the verbosity of the Logger
import SwiftUI
struct LoggerVerbosityPicker: View {
/// User defaults value.
@AppStorage(Logger.defaultsKey) private var storedSelection: String?
/// Current selection.
@State var selection: Logger.Verbosity = Logger.Verbosity.verbose
var body: some View {
Picker("Verbosity", selection: $selection) {
ForEach(Logger.Verbosity.allCases, id: \.self) {
Text($0.rawValue)
}
}
.pickerStyle(.segmented)
.onAppear {
if let storedSelection,
let verbosity = Logger.Verbosity(rawValue: storedSelection) {
selection = verbosity
}
}
.onChange(of: selection) { newValue in
Logger.verbosity = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment