xcode调试技巧

来源:互联网 发布:中国式理财软件下载 编辑:程序博客网 时间:2024/04/29 06:55

在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

原创粉丝点击