首页 > 其他 > 详细

ios调试技巧

时间:2014-02-15 05:15:23      阅读:361      评论:0      收藏:0      [点我收藏+]

自动预编译(针对全工程)

Config.h

bubuko.com,布布扣
//网络接口部分,get\post路径

//查三个点与__VA_ARGS__关系,自定义NSLog

#ifdef DEBUG
#define DMLog(...) \
NSLog(@"%s %@",__PRETTY_FUNCTION__,[NSString stringWithFormat:__VA_ARGS__])

#else
#define DMLog(...) do { } while(0)

#endif
bubuko.com,布布扣

在*-prefix.pch文件上#import "Config.h"


 

AppDelegate.m

bubuko.com,布布扣
//调试技巧1
    NSLog(@"%d行,方法%s",__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(@"不管是不是都执行,常用关闭和释放");
    }
bubuko.com,布布扣

 2.

bubuko.com,布布扣

3.

bubuko.com,布布扣

4.DEBUG调试查考:http://blog.csdn.net/liangguo03/article/details/7958903#1536434-tsina-1-54165-66a1f5d8f89e9ad52626f6f40fdeadaa

5.

bubuko.com,布布扣

bubuko.com,布布扣 

ios调试技巧

原文:http://www.cnblogs.com/huen/p/3549391.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!