iOS开发小技巧总结20150318

一、更增强大的Log输出

#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), PRETTY_FUNCTION, LINE, ##VA_ARGS);html

NSInteger numberA = 100;
DLog(@"numberA is %ld",numberA);
NSArray *arrayA = @[@"A",@"B",@"C"];
DLog(@"arrayA is %@",arrayA);

效果图
打印的内容包括所在的类,所在的方法,所在行数。布局

二、布局时候使用CGRectInset,设置左右、上下边距

UIView *blackView = [[UIView alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 30)];
blackView.backgroundColor = [UIColor blackColor];
[self.view addSubview:blackView];

左右边距十、上下边距30

三、CFAbsoluteTimeGetCurrent()计算时间差

NSTimeInterval startTime = CFAbsoluteTimeGetCurrent();
NSURL *url = [NSURL URLWithString:@"http://m.weather.com.cn/atad/101280601.html"];
NSData *data = [NSData dataWithContentsOfURL:url];
DLog(@"data is %@",data);
NSTimeInterval endTime = CFAbsoluteTimeGetCurrent();
DLog(@"time gap is %f",endTime - startTime);

在主线程处理数据花了18.27秒,醉了

四、

相关文章
相关标签/搜索