AZDebugUtil 是一款用于 iOS 开发的调试日志到控制台/UI/文件的工具。使用 NSLog 的替代品,可以很容易地通过预处理器管理日志语句。您还可以轻松地将日志保存到文件中。
要运行示例项目,克隆仓库,首先从 Example 目录运行 pod install
。
AZDebugUtil 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行
pod "AZDebugUtil"
#import "Debug.h"
。如果不存在,可以创建一个,然后更新 Build Settings
> Apple LLVM - Language
> Prefix Header
中的设置Debug.h
将预编译定义复制到 prefix header 文件中,并根据需要取消注释它们UIApplicationDelegate
的 application:didFinishLaunchingWithOptions:
中调用 [DebugLogView sharedView]
以初始化日志 UI,如果需要在 UI 上查看日志DebugLog
、DebugLogError
、FileLogger
等等DebugLog(@"we got here: %d", theId);
DebugLogWarning(@"the name is nil for people: %@", people.uid);
DebugLogError(@"should never get here");
[FileLogger log:@"we got %d peoples here", peoples.count];
[DebugTip show:@"Hello!"];
[UIAlertView showWithTitle:@"Hi" message:@"show the value?" onDismiss:
^(UIAlertView *alertView, NSInteger buttonIndex) {
if(buttonIndex != alertView.cancelButtonIndex){
[self showDebugValue];
}
} cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
DebugLogView
)。请注意,出于性能考虑,DebugLogView
默认是禁用的。当您开启它时,窗口上会有一个小按钮 "[D]",点击它将打开视图。在视图中有一个开关来启用日志。在发布之前,应取消定义(或简单地评论)上述所有预处理器。