views:

240

answers:

2

I am struggling to understand why the following code doesn't show an array with any contents when I debug in XCode and yet the NSLog clearly displays contents, as does GDB using po?

- (IBAction)action: (id)sender {

NSMutableArray *btnTitles = [NSMutableArray arrayWithObject: @"Open in Safari"];
NSLog(@"%@",[btnTitles description]); // in xcode - btnTitles shows 0 elements, nslog shows 1?

if ([MFMailComposeViewController canSendMail]) {
 [btnTitles addObject: @"Email Article"];
}
NSLog(@"%@, %i",[btnTitles description], [btnTitles count]); // in xcode still shows 0 items, nslog shows 2

I am using Snow Leopard and Xcode 3.2.1 - and at first I thought my variable was being released, however the NSLog and using GDB seem to indicate that everything is fine. However when I hover over the btnTitles variable it shows - (variable 0 objects). Similarly, if I do Open In Window for that variable, it has a title: btnTitles[(null)()-(null)] and it shows variable, 0 objects). Yet in the console I am seeing:

2009-12-20 14:29:03.352 MyApp[11125:207] (
    "Open in Safari"
)
2009-12-20 14:29:05.499 MyApp[11125:207] (
    "Open in Safari",
    "Email Article"
), 2

This has me stumped - the code looks like it should be ok - I am initialising the variable correctly (I have tried doing retain as well).

Can anyone spot what I am doing wrong, or is this a bug in the the new XCode on Snow Leopard?

Tim

A: 

when you try to show the array's contents in GDB, are you sure that you've already executed the lines that add the strings to it?

NSResponder
Yes the breakpoints are on the NSLog stmts and in Xcode it shows no contents but Gdb and Nslog show contents. It's very weird and had me confused for ages until I thought to log the results.
TimM
A: 

NSArrays are objects. They aren't supposed to show up as regular C arrays whose contents you can browse simply by looking at its starting memory address.

Azeem.Butt