最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】Xcode中的调试功能,真尼玛太垃圾了!!!

Xcode crifan 7503浏览 0评论

最近在用Xcode调试iOS程序,发现里面的调试功能,不是一般的垃圾。下面好好抱怨一下。

 

1.极其不方便查看变量值

此处贴上相关的源代码:

BirdSighting.h:

//
//  BirdSighting.h

#import <Foundation/Foundation.h>

@interface BirdSighting : NSObject  <NSCoding>
{

}

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *location;
@property (nonatomic, strong) NSDate *date;
@property (nonatomic) UIImage *image;

 

BirdSightingDataController.h:

//
//  BirdSightingDataController.h

#import <Foundation/Foundation.h>

@class BirdSighting;

@interface BirdSightingDataController : NSObject
{
}

@property (nonatomic, copy)NSMutableArray *masterBirdSightingList;

- (void)saveBirdSightingList;

@end

 

BirdSightingDataController.m:

//
//  BirdSightingDataController.m
//  BirdWatching
//
//  Created by li crifan on 12-8-21.
//  Copyright (c) 2012年 li crifan. All rights reserved.
//

#import "BirdSightingDataController.h"
#import "BirdSighting.h"

@interface BirdSightingDataController()
-(void)initializeDefaultDataList;
@end

@implementation BirdSightingDataController

-(void)initializeDefaultDataList{  
    //restore data
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSData *savedEncodedData = [defaults objectForKey:@"BirdSightingList"];
    if(savedEncodedData == nil)
    {
        NSMutableArray *sightingList = [[NSMutableArray alloc] init];
        self.masterBirdSightingList = sightingList;
    }
    else{
        self.masterBirdSightingList = (NSMutableArray *)[NSKeyedUnarchiver unarchiveObjectWithData:savedEncodedData];
    }
}


-(void)setMasterBirdSightingList:(NSMutableArray *)newList{
    if(_masterBirdSightingList != newList)
    {
        _masterBirdSightingList = [newList mutableCopy];
    }
}

-(void)addBirdSightingWithName:(NSString *)inputBirdName location:(NSString *)inputLocation date:(NSDate *)date image:(UIImage *)image{
    BirdSighting *sighting;
    //NSDate *today = [NSDate date];
    //sighting = [[BirdSighting alloc]initWithName:inputBirdName location:inputLocation date:today];
    sighting = [[BirdSighting alloc]initWithName:inputBirdName location:inputLocation date:date image:image];
    [self.masterBirdSightingList addObject:sighting];
    
    [self saveBirdSightingList];
}

- (void)saveBirdSightingList{
    //    NSData *encodedSingleObj = [NSKeyedArchiver archivedDataWithRootObject:sighting];
    //    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    //    [defaults setObject:encodedSingleObj forKey:@"SingleBirdSightingObject"];
    
    //save data
    NSData *encodedCurBirdSightingList = [NSKeyedArchiver archivedDataWithRootObject:self.masterBirdSightingList];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:encodedCurBirdSightingList forKey:@"BirdSightingList"];
    [defaults synchronize];
}

@end

 

对于上述代码,想要调试查看self.dataController.masterBirdSightingList的值:

debug self.dataController.masterBirdSightingList

很明显,目前已经的调试功能,虽然是可以看到self下的dataController下的masterBirdSightingList,但是也只是显示出其是个数组__NSArrayM,

对应的地址是0x6dd2d20,里面包含3个对象。

其他更多的信息,本以为点击那个向右的箭头:

right arrow

可以显示出其下相关的变量的呢,结果却是空白的:

show null more info

 

而对于masterBirdSightingList中的每个BirdSighting变量的值,都无法查看到了。

 

然后也继续去折腾了试试其他办法是否可以查看到对应的数据。

 

双击对应的masterBirdSightingList,可以显示出对应的编辑窗口:

double click show edit window

 

后来找了半天,唯一尼玛有点用的,是这个右击变量后选择“Print Description of xxx”:

print desc info

所打印出来的信息:

Printing description of self->_dataController->_masterBirdSightingList:

<__NSArrayM 0x6dd2d20>(

<BirdSighting: 0x6dd2f40>,

<BirdSighting: 0x6dd3bb0>,

<BirdSighting: 0x6dd4a50>

)

printed value info

 

终于算是看到了masterBirdSightingList下的BirdSighting的影子了。

然后就接着想办法去查看每个BirdSighting的值。

 

2.内存查看窗口,效果也很不好

然后对于上述已经知道了每个BirdSighting的地址了,想要去打开对应的内存监视窗口,貌似也没找到。

后来还是右击masterBirdSightingList,然后选择View Memory for _masterBirdSightingList:

view memory xxx

而打开的内存调试窗口:

mem window

 

不过后来还是找到了打开内存窗口的位置:

Product -> Debug -> View Memory

open mem view

 

但是对于内存的值查看,还是不是很好用。

 

而对于此处想要查看之前所说的三个BirdSighting,结果只能靠自己手动输入对应的值查看了:

inpu mem addr can see content

对应的每页查看大小,是可以设置的:

page bytes

 

如此,一点点输入地址,结果对于变量的值的查看,也还是,除了个别字符串的值,比如我此处的BirdName的string,其他的基本看不懂。

 

所以,总是,查看变量值,内存监视等,都很不好用。

 

3.无法添加监视某个值

无法直接点击某个值,然后加入调试窗口,然后实现始终可以监视该变量的值。

no watch some value

最接近的是,点击某个已经在Debug窗口中出现的变量,然后选择Watch xxx:

watch current selected value

但是没太搞懂,因为本身当前变量已经在debug窗口了,还添加个啥啊?

 

5.如何调试/查看数组变量

参考:

Xcode 4 debugging

去设置该变量为private:

@interface BirdSightingDataController : NSObject
{
    @private NSMutableArray *masterBirdSightingList;
}

@property (nonatomic, copy)NSMutableArray *masterBirdSightingList;

然后试试调试效果。

结果却看到的新添加的private的变量是空的值:

new private value is null

所以,意思是,如果变量为private的interface变量,那也是可以实时显示其变量值的。

但是对于property变量,却无法查看详细的值。

此处知道这个暂时就行了,等以后有需要的话,再把变量改为private的interface变量。

但是很奇怪的,为何property变量,就无法直接查看其值呢?

难道Mac的Xcode的开发人员,连这点功能都没能力实现?

不清楚,求高手解释。

 

6.关于Xcode vs VS(Visual Studio)

关于VS和Xcode的对比,找到这个:

Xcode 4.3 vs Visual Studio 11 beta

没有去细看,但是很同意其总结:

比起Windows的Visual Studio的功能,Xcode还是差很多的。

 

【总结】

总之,目前的感觉,Xcode的调试功能,不要太挫,太弱啊。

当然,上述只是我个人感觉。

如有高手知道有其他更好用的调试方法,还请告知。

转载请注明:在路上 » 【整理】Xcode中的调试功能,真尼玛太垃圾了!!!

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (9)

  1. 捂脸/// GCD白瞎了,这吐槽看得我醉了。
    欧阳生8年前 (2016-10-19)回复
  2. 赞同啊,那些说选择语言不重要,语言只是个工具的我想打的他老妈都不认识,让他还出来装逼.信了邪才选择了做iOS用这个烂IDE浪费青春
    帅逼8年前 (2016-09-08)回复
  3. 旁边的GDB要哭了...
    AA9年前 (2014-11-24)回复
    • 哈哈,不会用 lldb 的家伙,抱怨是必然的
      HAHA8年前 (2015-11-24)回复
      • 去试了试,虽然lldb在命令行中可以做N多事情,但是还是没有鼠标+界面显示来的方便-》所以还是没有VisualStudio之类的工具在调试方面做得爽啊。
        crifan8年前 (2015-12-03)回复
  4. 确实,居然还有人说xcode好用,估计只用过这个垃圾,我觉得这东西都不配叫做ide
    l10年前 (2014-04-13)回复
    • 恩,有了对比,才知道什么叫好用。
      crifan10年前 (2014-04-22)回复
  5. 是挺垃圾的,不过聊胜于无了。 watch的用法是很诡异,添加完watch后,看不到被watch的列表……不过watch的作用是,在该值被改变的时候,断点会自动触发,在某些场合还是挺有用的
    laoyur10年前 (2014-04-01)回复
  6. 的确垃圾,不是一般的难用,比起eclipse和visual studio差多了!
    justtest11年前 (2013-09-17)回复
89 queries in 0.177 seconds, using 22.19MB memory