Select File > Swift Packages > Add Package Dependency. Enter https://github.com/noppefoxwolf/DebugMenu in the "Choose Package Repository" dialog.
#if DEBUG
DebugMenu.install(windowScene: windowScene, items: [
ViewControllerDebugItem<ColorViewController>(),
ClearCacheDebugItem(),
UserDefaultsResetDebugItem(),
CustomDebugItem()
], complication: [
CPUUsageComplication()
])
#endif
@main
struct App: SwiftUI.App {
var body: some Scene {
WindowGroup {
Root.View(
store: .init(
initialState: .init(),
reducer: Root.reducer,
environment: .debug
)
).debugMenu(debuggerItems: [
ViewControllerDebugItem<ColorViewController>(),
ClearCacheDebugItem(),
UserDefaultsResetDebugItem(),
CustomDebugItem()
], complication: [
CPUUsageComplication()
])
}
}
}
struct CustomDebugItem: DebugMenuPresentable {
let debuggerItemTitle: String = "Custom item"
let action: DebugMenuAction = .toggle { UserDefaults.standard.bool(forKey: "key") } action: { (isOn, completions) in
let userDefaults = UserDefaults.standard
userDefaults.set(isOn, forKey: "key")
if userDefaults.synchronize() {
completions(.success(message: "Switch to \(isOn)"))
} else {
completions(.failure(message: "Failed to save"))
}
}
}
public class CustomComplication: ComplicationPresentable {
public init() {}
public func startMonitoring() {}
public func stopMonitoring() {}
public let fetcher: MetricsFetcher = .text {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm:ss"
return formatter.string(from: Date())
}
public var title: String = "Date"
}
Tap floating bug button.
Longpress floating bug button, and tap Show widget
.
License DebugMenu is released under the MIT license. See LICENSE for details.