PerfectDebug

PerfectDebug


License
MIT
Install
pod try PerfectDebug

Documentation

PerfectDebug

CocoaPods Platform License

PerfectDebug 是一个轻量级的 iOS 调试日志工具库,旨在帮助开发者快速定位和解决问题。它提供了便捷的日志面板等功能,适用于开发和测试阶段。

功能特性

  • 快捷键管理:模拟器快捷键设置。
  • 网络监听: 自动监听网络请求信息。
  • 设备指标监控: MEM/CPU/FPS。
  • 日志面板:支持灵活的日志记录,方便调试网络请求和自定义日志。
  • 轻量级:无侵入性设计,易于集成到现有项目。

安装

CocoaPods

PerfectDebug 可以通过 CocoaPods 安装。编辑你的 Podfile,添加以下内容:

pod 'PerfectDebug'

然后运行以下命令:

pod install

手动安装

如果你不想使用 CocoaPods,也可以手动将 PerfectDebug 集成到你的项目中:

  1. PerfectDebug 仓库克隆到本地:
git clone https://github.com/rggsix/PerfectDebug.git
  1. 将 PerfectDebug 文件夹拖入你的 Xcode 项目。
  2. 在 Xcode 中,确保 PerfectDebug 已添加到你的目标(Target)中。

使用方法

初始化

在你的 AppDelegateSceneDelegate 中初始化 PerfectDebug

import PerfectDebug

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
        //  初始化 PerfectDebug
        PerfectDebug.shared().isOn = true
        //  网络+性能监听
        PerfectDebug.config(.init(rawValue: PerfectDebugModule.netMonitor.rawValue | PerfectDebugModule.performance.rawValue) ?? .netMonitor)
#endif

        //  记录一个日志 (建议Tag非空)
        PerfectDebug.log(withTag: "AppLifecycle", content: [
            "type": "didFinishLaunchingWithOptions",
            "launchOptions": launchOptions ?? [:]
        ])
    }
}

可选配置

//  自定义日志列表中的缩略内容
PerfectDebug.shared().registerAbstractProvider(forTag: "SomeIgnoredTag") { tag, contentDict in
    return contentDict["name"] as? String ?? "Unknown"
}

//  自定义判断 网络请求请求成功 or 失败, 失败请求在日志面板中将以红色展示
DebugNetworkMonitor.shared().responseJudgeBlock = { _, response in
    return ((response?["data"] as? [String: Any])?["code"] as? Int) != 0
}
        
//  需要忽略的网络请求 host
DebugNetworkMonitor.shared().ignoreUrlList = [ "some.thirdparty-api.com" ]

添加快捷键监听

可以为模拟器增加监听快捷键, 让View或VC的某个Responder在按下电脑键盘对应快捷键时, 发起响应

@objc class SomeViewOrVC: ParentViewOrVC {
    //  你的业务代码...
    var skipButton = UIButton()

#if DEBUG
    @objc override func wm_debugShortcutKeys() -> [WMDSKey] {
        return [
            //  当你在电脑上按下空格, 模拟器中这个View的 skipButton 点击事件会被触发
            WMDSKey(keyType: .keySpacebar, responder: self.skipButton)
        ]
    }
#endif
}

要求

  • iOS 12.0 或更高版本
  • Xcode 15.0 或更高版本
  • Swift 5.0 或更高版本

贡献

欢迎为 PerfectDebug 贡献代码!请按照以下步骤操作:

  1. Fork 本仓库。
  2. 创建你的功能分支(git checkout -b feature/AmazingFeature)。
  3. 提交你的更改(git commit -m 'Add some AmazingFeature')。
  4. 推送到分支(git push origin feature/AmazingFeature)。
  5. 创建一个 Pull Request。 请确保你的代码符合 Swift 编码规范。

许可证

PerfectDebug 使用 MIT 许可证。详情请查看文件

联系方式

如果有任何问题或建议,请通过以下方式联系我们: