#import "ViewController.h"
@interface ViewController ()
@end
//作為初學(xué)者到今天才接觸到 ifdef,else,endif 的用法,才發(fā)現(xiàn)挺實(shí)用的.至少在開發(fā)中你可以靈活切換debug模式
//此處是定義DEEBUG
#define DEEBUG 1
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self debugIfdef];
[self debugIfndef];
[self debugIf];
}
//如果程序開頭有#define DEEBUG這行,碰到下面#ifdef DEEBUG的時(shí)候,當(dāng)然執(zhí)行第一個(gè)NSLog.否則第二個(gè)NSLog將被執(zhí)行.
//我認(rèn)為用這種可以很方便的開啟/關(guān)閉整個(gè)程序的某項(xiàng)特定功能.
- (void)debugIfdef {
#ifdef DEEBUG
NSLog(@"DEEBUG 已定義");
#else
NSLog(@"DEEBUG 未定義");
#endif
}
//這里正好和上面的相反
- (void)debugIfndef {
#ifndef DEEBUG
NSLog(@"DEEBUG 已定義");
#else
NSLog(@"DEEBUG 未定義");
#endif
}
//這里表示,如果常量為真(非0,隨便什么數(shù)字,只要不是0)就執(zhí)行程序段1,否則執(zhí)行程序段2.
//我認(rèn)為這種方法可以將測試代碼加進(jìn)來.當(dāng)需要開啟測試的時(shí)候,只要將常量變1就好了.而不要測試的時(shí)候,只要將常量變0。
- (void)debugIf {
#if DEEBUG
NSLog(@"DEEBUG 已定義");
#else
NSLog(@"DEEBUG 已定義");
#endif
}