views:

67

answers:

2

I'd like to display the contents of the property 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.

+1  A: 

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?

vodkhang
gdb expressions are not terminated by semi-colons
Brad Smith
Print Description uses the same functionality as print-object in GDB. (They both call `-debugDescription` on the result of the expression.) As Brad Smith demonstrated, the OP's approach (`po [[Session sharedManager] myarray]`) should work fine, there are no syntax errors.
Quinn Taylor
I don't see Print Description when the breakpoint is hit. Can you elaborate on how to access it?
4thSpace
Usually you can get to it by right-clicking on the variable in the debugger view.
Quinn Taylor
@Brad Smith: uhm, I got it, because at the first time, I think that it's normal code.@Quinn Taylor: thanks for editting:)
vodkhang
+1  A: 

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.

Brad Smith
Yes - you are correct. It does work. I've updated my OP, since it had a typo. Thanks.
4thSpace