歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> iOS學習之Xcode 的Debug技巧

iOS學習之Xcode 的Debug技巧

日期:2017/3/1 10:16:20   编辑:Linux編程

在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

Copyright © Linux教程網 All Rights Reserved