Objective-C 文法之 Debug 運算式

來源:互聯網
上載者:User

標籤:

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 : NSObject4 + (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]): TestClass13 [[NSString stringWithUTF8String:__FILE__] lastPathComponent]: TestClass.m

 

Objective-C 文法之 Debug 運算式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.