开发者

How to display complex object in debugger?

I'd like to display the contents of the property开发者_如何学C myarray, from the following singleton:

[Session sharedManager].myarray

I've tried these:

po [Session sharedManager]. myarray

po [[Session sharedManager] myarray]

but always get this error:

A syntax error near end of expression.

Any suggestions?

--- EDIT ---

I'm working with SDK 3.0.

I've discovered the problem, which is I had three open brackets rather than two. You can't see that here because I mistyped the number of brackets. It is working now. Thanks.


If you use XCode Debugger and you set a breakpoint in the some place that the variable is already initialized and can be seen, you can click to the variable and choosing Print Description.

You can do it in simple way like NSLog(). What is the problem with this approach? Usually, I see that it will print out all the description() method of all objects in the array?

And I am not sure, but you lack a semicolon at the end of the statement. ";", can you recheck for that one?


What you are describing is very strange. I set up a test application and was able to print the object from the singleton just fine.

#import "testAppDelegate.h"

//A Session Singleton
@interface Session : NSObject {
    NSArray *myArray;
}
@property (nonatomic, retain)   NSArray *myArray;
@end

@implementation Session
@synthesize myArray;
static Session *sharedSession;
+(Session *)sharedSession {
    if (!sharedSession) {
        sharedSession = [[Session alloc] init];
        sharedSession.myArray = [NSArray arrayWithObjects:@"A",@"B",@"C",nil];
    }
    return sharedSession;
}
@end


//App Delegate
@implementation testAppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    NSLog(@"%@",@"Breakpoint Here"); //Here is where I set My breakpoint
    return YES;
}


- (void)dealloc {
    [super dealloc];
}

@end

In GDB:

(gdb) po [[Session sharedSession] myArray]
<NSCFArray 0x4710630>(
A,
B,
C
)

I did this using the 3.2 iPhone SDK, using a default project template, in the debug mode without changing any build settings. I suspect you may have issues in your build settings. I have noticed that debugging is wonky on the 4.0 beta sdks. If you are using 4.0, remember that it is still beta, and your problems may really be someone else's problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜