Basil Bourque
Basil Bourque

Reputation: 340350

Why is [NSNumber numberWithBool:YES] reported as null by debugger?

After running these two lines in Xcode 4.6.3, both x and y are marked as (null) with grey text in the debugger’s Variables View pane.

  NSNumber* y = [NSNumber numberWithBool:YES];
  NSNumber* z = [NSNumber numberWithBool:NO];

Ditto for:

  NSNumber* literalYes = @YES;
  NSNumber* literalNo = @NO;

Yet if I context-click on those items in the Variables View pane, and from the context menu choose Print Description, I do see the correct 1 or 0 value.

Why does the debugger’s Variables View pane report these objects as null when they are not?

Upvotes: 1

Views: 2474

Answers (1)

Basil Bourque
Basil Bourque

Reputation: 340350

Xcode 4 debugger lies. (See comment above by Herrman Klecker)

Ignore the grey color text "(null)".

Look at this question, Xcode debugging: View value of NSNumber?, for tips on displaying actual values.

One way… Set breakpoint after your code, click into the debugger Console View, and use the Print Object command by typing po y. Press Return/Enter to execute the expression and see resulting value in the console. The commands p and po work in both the older gdb and newer lldb debugger technologies. See Debugging tips for Objective-C programming for examples.

Another way… Open the Debugger view and in the Summary column enter something like: {(int)[$VAR intValue]}

Upvotes: 1

Related Questions