nslog一些官方文档中的知识备忘
来源:互联网 发布:linux编辑shell脚本 编辑:程序博客网 时间:2024/04/30 11:08
官方文档学习的关于NSLOG的知识:
主要是预编译宏定义
1.
__PRETTY_FUNCTION__
可以获取到当前的类和方法,例如:
- (void)pressButton:(id)sender
{
NSLog( @"calling: %s", __PRETTY_FUNCTION__ );
....
这个东西是用来输出被调用的函数的名字的,这在存在很多代理方法时分析代码调用情况是非常有用的,可以让你非常好的理解代码执行的顺序。
上面这行会再控制台输出:calling: -[MyObjectClassName pressButton:]
Here, the pre-defined compile time variable __PRETTY_FUNCTION__ (a C style string) is used to print the name of the function being called. This technique is especially useful when you are analyzing code using lots of delegates and you would like to understand the sequence in which calls are being made to your delegate's methods.
The above will print the following in the console:
calling: -[MyObjectClassName pressButton:]
延伸:
Table 1 Preprocessor macros and for logging in C/C++/Objective-C.
Macro
Format Specifier
Description
__func__
%s
Current function signature.
__LINE__
%d
Current line number in the source code file.
__FILE__
%s
Full path to the source code file.
__PRETTY_FUNCTION__
%s
Like __func__, but includes verbose type information in C++ code.
Table 2 Expressions for logging in Objective-C.
Expression
Format Specifier
Description
NSStringFromSelector(_cmd)
%@
Name of the current selector.
NSStringFromClass([self class])
%@
Name of the current object's class.
[[NSString stringWithUTF8String:__FILE__] lastPathComponent]
%@
Name of the source code file.
[NSThread callStackSymbols]
%@
NSArray of the current stack trace as programmer-readable strings. For debugging only, do not present it to end users or use to do any logic in your program
2.nslog 中使用类似于回朔/回顾方法执行顺序的东东。崩溃的时候比较有用,尤其是维护其他人的应用时。
NSLog(@"%@", [NSThread callStackSymbols]);
下面有一个使用这个方法的例子:
2014-04-30 18:44:30.075 AVCustomEdit[52779:60b] (
0 AVCustomEdit 0x0000efa6 -[APLSimpleEditor buildCompositionObjectsForPlayback:] + 278
1 AVCustomEdit 0x0000686e -[APLViewController viewDidAppear:] + 590
2 UIKit 0x007a4099 -[UIViewController _setViewAppearState:isAnimating:] + 526
3 UIKit 0x007a4617 -[UIViewController __viewDidAppear:] + 146
4 UIKit 0x007a49aa -[UIViewController _executeAfterAppearanceBlock] + 63
5 UIKit 0x0069f0d0 ___afterCACommitHandler_block_invoke_2 + 33
6 UIKit 0x0069f055 _applyBlockToCFArrayCopiedToStack + 403
7 UIKit 0x0069ee9a _afterCACommitHandler + 568
8 CoreFoundation 0x029db2bf __CFRunLoopDoObservers + 399
9 CoreFoundation 0x029b9254 __CFRunLoopRun + 1076
10 CoreFoundation 0x029b89d3 CFRunLoopRunSpecific + 467
11 CoreFoundation 0x029b87eb CFRunLoopRunInMode + 123
12 GraphicsServices 0x0318b5ee GSEventRunModal + 192
13 GraphicsServices 0x0318b42b GSEventRun + 104
14 UIKit 0x00681f9b UIApplicationMain + 1225
15 AVCustomEdit 0x000026bd main + 141
16 libdyld.dylib 0x0269e701 start + 1
)
3。
- nslog一些官方文档中的知识备忘
- 一些参考文档备忘
- 收藏一些官方文档
- theano中的一些备忘
- delphi的一些小知识,备忘
- 【备忘】c++重载的一些知识
- Jmeter中的一些应用备忘
- zigbee中的一些知识
- Elasticsearch中的一些知识
- 命令行中的一些知识
- Google 官方的一些内存管理文档
- angular.js官方文档的一些说明
- 备忘知识
- XSLT 学习记录(一些语法和知识,备忘)
- iOS官方文档中的宏定义
- 文档和翻译的一些知识
- SQL Server中的一些知识
- Oracle 中的一些小知识
- 设计模式之策略模式---Strategy Pattern
- 桌面小部件
- VirtualBox中安装CentOS使得在ssh和外网都能正常链接
- HI3516A stride的理解.
- Ecshop二次开发之自定义库文件和模板数据调用
- nslog一些官方文档中的知识备忘
- Cloudera的CDH和Apache的Hadoop的区别
- mysql 用户管理
- ecshop 二次开发,源码分析
- 文件流操作
- 我的第一篇博文
- 项目____get提交与post提交乱码的问题
- java把网页报存为图片的框架
- ecshop二次开发的简单实例说明