• iOS学习之Xcode 的Debug技巧


      在Xcode中,Debug时,不能像eclipse ,或VS那些集成开发那样,能直接查看变量的值。那怎么在调试的时候查看XCode的变量呢?

    有一些方法的。

    1、新建一个Single View App

    在viewDidLoad里添加些代码:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1",@"key1",
                             @"28", @"age",@"rongfzh",@"name" ,nil];
        
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(20, 40, 250, 60);
        label.text = [dic objectForKey:@"name"];
        [self.view addSubview:label];
    }

    在最后一行打上断点。

    2、"po" : print object 命令 打印出对象。

    Command+R调试运行,在 Debug Console 上lldb上输入po dic回车,显示如下:

    这就把词典内容打印出来了。

    再打印label试试。

    (lldb) po label

    (UILabel *) $3 = 0x06a8bdd0 <UILabel: 0x6a8bdd0; frame = (20 40; 250 60); text = 'rongfzh'; clipsToBounds = YES;userInteractionEnabled = NO; layer = <CALayer: 0x6a8be90>>

    label的信息也打印出来了。

    3、print命令

    print (char*)[[dic description] cString]

    (char *) $4 = 0x06d79760 "{     age = 28;     key1 = value1;     name = rongfzh; }"

    打印对象的retainCount,但对象被回收

    (lldb) print (int)[label retainCount]

    (int) $2 = 1


  • 相关阅读:
    搭建DHCP服务
    sshd免密登陆
    加密类型以及数据加密解密过程
    搭建私有CA并实现证书颁发
    CentOS 7 启动流程
    Linux命令:tcpdump命令
    Linux命令:ping命令
    Linux命令:ss命令
    Linux命令:ip命令
    Linux命令:netstat命令
  • 原文地址:https://www.cnblogs.com/songfeixiang/p/3733681.html
Copyright © 2020-2023  润新知