现在的位置: 首页 > 综合 > 正文

iOS学习之Xcode 的Debug技巧

2014年09月05日 ⁄ 综合 ⁄ 共 892字 ⁄ 字号 评论关闭

  在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 "{\n    age = 28;\n    key1 = value1;\n    name = rongfzh;\n}"

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

(lldb) print (int)[label retainCount]

(int) $2 = 1

抱歉!评论已关闭.