在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
main.m 1 #import <Foundation/Foundation.h> 2 #import "TestClass.h" 3 4 int main(int argc, const char * argv[]) { 5 @autoreleasepool { 6 NSString *purposeInfo = @"拿到的信息不仅在Debug中有用,而且在selector的传递也很有用"; 7 [TestClass testDebugKeyword:purposeInfo]; 8 } 9 return 0; 10 } TestClass.h 1 #import <Foundation/Foundation.h> 2 3 @interface TestClass : NSObject 4 + (void)testDebugKeyword:(NSString *)purposeInfo; 5 6 @end TestClass.m 1 #import "TestClass.h" 2 3 @implementation TestClass 4 5 + (void)testDebugKeyword:(NSString *)purposeInfo { 6 NSMutableString *mStrInfo = [[NSMutableString alloc] initWithString:purposeInfo]; 7 [mStrInfo appendString:@"\n\nDebug时一些系统预留定义词的用法如下:\n"]; 8 [mStrInfo appendFormat:@"__func__: %s\n", __func__]; 9 [mStrInfo appendFormat:@"__PRETTY_FUNCTION__: %s\n", __PRETTY_FUNCTION__]; 10 [mStrInfo appendFormat:@"__LINE__: %d\n", __LINE__]; 11 [mStrInfo appendFormat:@"__FILE__: %s\n", __FILE__]; 12 13 [mStrInfo appendString:@"\n\nDebug时一些Core Foundation方法的用法如下:\n"]; 14 [mStrInfo appendFormat:@"NSStringFromSelector(_cmd): %@\n", NSStringFromSelector(_cmd)]; 15 [mStrInfo appendFormat:@"NSStringFromClass([self class]): %@\n", NSStringFromClass([self class])]; 16 [mStrInfo appendFormat:@"[[NSString stringWithUTF8String:__FILE__] lastPathComponent]: %@\n", [[NSString stringWithUTF8String:__FILE__] lastPathComponent]]; 17 18 NSLog(@"%@", mStrInfo); 19 } 20 21 @end
结果: 1 2015-06-20 11:07:16.353 OCDebugKeyword[465:18859] 拿到的信息不仅在Debug中有用,而且在selector的传递也很有用 2 3 Debug时一些系统预留定义词的用法如下: 4 __func__: +[TestClass testDebugKeyword:] 5 __PRETTY_FUNCTION__: +[TestClass testDebugKeyword:] 6 __LINE__: 18 7 __FILE__: /Users/Kenmu/Documents/iOSDevelopment/OCDebugKeyword/OCDebugKeyword/TestClass.m 8 9 10 Debug时一些Core Foundation方法的用法如下: 11 NSStringFromSelector(_cmd): testDebugKeyword: 12 NSStringFromClass([self class]): TestClass 13 [[NSString stringWithUTF8String:__FILE__] lastPathComponent]: TestClass.m
|
请发表评论