
- Objective-C基礎
- Objective-C - 首頁
- Objective-C - 概述
- Objective-C - 環境搭建
- Objective-C - 程式結構
- Objective-C - 基本語法
- Objective-C - 資料型別
- Objective-C - 變數
- Objective-C - 常量
- Objective-C - 運算子
- Objective-C - 迴圈
- Objective-C - 條件判斷
- Objective-C - 函式
- Objective-C - 塊 (Blocks)
- Objective-C - 數字
- Objective-C - 陣列
- Objective-C - 指標
- Objective-C - 字串
- Objective-C - 結構體
- Objective-C - 預處理器
- Objective-C - Typedef
- Objective-C - 型別轉換
- Objective-C - 日誌處理
- Objective-C - 錯誤處理
- 命令列引數
- 高階Objective-C
- Objective-C - 類與物件
- Objective-C - 繼承
- Objective-C - 多型
- Objective-C - 資料封裝
- Objective-C - 分類 (Categories)
- Objective-C - 模擬 (Posing)
- Objective-C - 擴充套件 (Extensions)
- Objective-C - 協議 (Protocols)
- Objective-C - 動態繫結
- Objective-C - 組合物件
- Obj-C - Foundation框架
- Objective-C - 快速列舉
- Obj-C - 記憶體管理
- Objective-C有用資源
- Objective-C - 快速指南
- Objective-C -有用資源
- Objective-C - 討論
Objective-C日誌處理
NSLog方法
為了列印日誌,我們在Objective-C程式語言中使用NSLog方法,從HelloWorld示例開始我們就一直在使用它。
讓我們看一段列印“Hello World”字樣的簡單程式碼:
#import <Foundation/Foundation.h> int main() { NSLog(@"Hello, World! \n"); return 0; }
現在,當我們編譯並執行程式時,我們將得到以下結果。
2013-09-16 00:32:50.888 demo[16669] Hello, World!
在正式應用中停用日誌
由於我們在應用程式中使用的NSLog會列印在裝置的日誌中,在正式版本中列印日誌並不理想。因此,我們使用型別定義來列印日誌,我們可以像下面這樣使用它們。
#import <Foundation/Foundation.h> #if DEBUG == 0 #define DebugLog(...) #elif DEBUG == 1 #define DebugLog(...) NSLog(__VA_ARGS__) #endif int main() { DebugLog(@"Debug log, our custom addition gets \ printed during debug only" ); NSLog(@"NSLog gets printed always" ); return 0; }
現在,當我們在除錯模式下編譯並執行程式時,我們將得到以下結果。
2013-09-11 02:47:07.723 demo[618] Debug log, our custom addition gets printed during debug only 2013-09-11 02:47:07.723 demo[618] NSLog gets printed always
現在,當我們在釋出模式下編譯並執行程式時,我們將得到以下結果。
2013-09-11 02:47:45.248 demo[3158] NSLog gets printed always
廣告