PerfectDebug
是一个轻量级的 iOS 调试日志工具库,旨在帮助开发者快速定位和解决问题。它提供了便捷的日志面板等功能,适用于开发和测试阶段。
- 快捷键管理:模拟器快捷键设置。
- 网络监听: 自动监听网络请求信息。
- 设备指标监控: MEM/CPU/FPS。
- 日志面板:支持灵活的日志记录,方便调试网络请求和自定义日志。
- 轻量级:无侵入性设计,易于集成到现有项目。
PerfectDebug
可以通过 CocoaPods 安装。编辑你的 Podfile
,添加以下内容:
pod 'PerfectDebug'
然后运行以下命令:
pod install
如果你不想使用 CocoaPods
,也可以手动将 PerfectDebug
集成到你的项目中:
- 将
PerfectDebug
仓库克隆到本地:
git clone https://github.com/rggsix/PerfectDebug.git
- 将 PerfectDebug 文件夹拖入你的 Xcode 项目。
- 在 Xcode 中,确保 PerfectDebug 已添加到你的目标(Target)中。
在你的 AppDelegate
或 SceneDelegate
中初始化 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 贡献代码!请按照以下步骤操作:
- Fork 本仓库。
- 创建你的功能分支(git checkout -b feature/AmazingFeature)。
- 提交你的更改(git commit -m 'Add some AmazingFeature')。
- 推送到分支(git push origin feature/AmazingFeature)。
- 创建一个 Pull Request。 请确保你的代码符合 Swift 编码规范。
PerfectDebug 使用 MIT 许可证。详情请查看文件。
如果有任何问题或建议,请通过以下方式联系我们:
- 邮箱:songhengdsg@icloud.com
- GitHub Issues:https://github.com/rggsix/PerfectDebug/issues