目录

DebugMenu

Installation

Swift Package Manager

Select File > Swift Packages > Add Package Dependency.

Enter https://github.com/noppefoxwolf/DebugMenu in the “Choose Package Repository” dialog.

.package(url: "https://github.com/noppefoxwolf/DebugMenu", from: "2.0.4")

Usage

UIKit based

#if DEBUG
DebugMenu.install(windowScene: windowScene, items: [
    ViewControllerDebugItem<ColorViewController>(),
    ClearCacheDebugItem(),
    UserDefaultsResetDebugItem(),
    CustomDebugItem()
], dashboardItems: [
    CPUUsageDashboardItem()
])
#endif

SwiftUI based

@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()
            ], dashboardItems: [
                CPUUsageDashboardItem()
            ])
        }
    }
}

Custom debug item

struct CustomDebugItem: DebugItem {
    let debugItemTitle: String = "Custom item"
    let action: DebugItemAction = .toggle { UserDefaults.standard.bool(forKey: "key") } action: { (isOn, completions) in
        let updater = Updater()
        do {
            await updater.update()
            return .success(message: "Updated")
        } catch {
            return .failure(message: "Faild to update")
        }
    }
}

Custom dashboard item

public class CustomDashboardItem: DashboardItem {
    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"
}

Exclude DebugMenu in production

Read following article. Linking a Swift package only in debug builds

How to use

Open DebugMenu

Tap floating bug button.

Show Dashboard

Longpress floating bug button, and tap Show widget.

License

License DebugMenu is released under the MIT license. See LICENSE for details.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号