自动预编译(针对全工程)
Config.h
在逗号和__VA_ARGS__之间的双井号,除了拼接前后文本之外,还有一个功能,那就是如果后方文本为空,那么它会将前面一个逗号吃掉。
//网络接口部分,get\post路径//查三个点与__VA_ARGS__关系,自定义NSLog#ifdef DEBUG#define DMLog(...) \NSLog(@"%s %@",__PRETTY_FUNCTION__,[NSString stringWithFormat:__VA_ARGS__])#else#define DMLog(format,...)\do {NSLog(format,##__VA_ARGS__);} \while(0)#endif
在*-prefix.pch文件上#import "Config.h"
2.屏幕适配
#define MAINFrame [UIScreen mainScreen].bounds
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEITHT [UIScreen mainScreen].bounds.size.height
AppDelegate.m
//调试技巧1 NSLog(@"文件名:%s,%d行,方法%s",__FILE__,__LINE__,__func__);//检测调用哪个方法 DMLog(@"123"); DMLog(@"%@",@"123"); /* //调试技巧2条件断点 for (int i = 0; i < 10 ; i++) { NSLog(@"start"); NSLog(@"%d",i); NSLog(@"end"); } //调试技巧3main函数下添异常断点 NSMutableArray *mArr = [[NSMutableArray alloc]init]; //[mArr addObject:nil]; [mArr addObject:@"67"]; NSString *str1 = @"123"; NSString *str2 = [str1 stringByAppendingString:@"abc"]; */ //调试4控制台命令 //调试5非ARC环境下异常 NSMutableString *str3 = [[NSMutableString alloc]init]; [str3 appendString:@"A"]; [str3 appendString:@"B"]; [str3 appendString:@"C"]; DMLog(@"str3 = %@",str3); /* [str3 release]; sleep(5); [str3 release]; [str3 release]; [str2 release]; */ //6异常处理 //自定义异常原因,抛出异常 float result = 0; float b = 0; result = 10 / b ; NSException *ex = [[NSException alloc]initWithName:@"MathException" reason:@"除数不为0" userInfo:nil]; @throw ex; NSObject *stu = nil; NSMutableArray *arr = [[NSMutableArray alloc]init]; @try//OC不常用,耗性能 { NSLog(@"可能发生的异常放在这,安全措施"); [arr addObject:stu]; } @catch (NSException *exception) { NSLog(@"try 操作异常"); NSLog(@"%@-%@",[exception name],[exception reason]); exit(-1); } @finally { NSLog(@"不管是不是都执行,常用关闭和释放"); }
1.__VA_ARGS__:http://blog.sina.com.cn/s/blog_661314940100qmfg.html
2.
3.
4.DEBUG调试查考:http://blog.csdn.net/liangguo03/article/details/7958903#1536434-tsina-1-54165-66a1f5d8f89e9ad52626f6f40fdeadaa
5.