Iphone – Why does XCode show the wrong object address in the debugger window

iphonexcode

My application tested whether my selectedViewController was equal to my moreNavigationController.

if( self.tabBarController.moreNavigationController == self.tabBarController.selectedViewController )
{
 // do something awesome.
}
else
{
  NSLog(@"No match");
}

The expression always evaluated false, so I started debugging. I put a breakpoint in the code and hovered my pointer over 'self', which caused the yellow cascading popup where I could see the addresses of both Controllers. The addresses were the same in the popup, which must be incorrect since the if statement failed. I see the same result in the debugger window.

I added these logging statements later, which revealed that the objects had 2 different addresses.

NSLog([NSString stringWithFormat:@"%d",(self.tabBarController.moreNavigationController)] );
NSLog([NSString stringWithFormat:@"%d",(self.tabBarController.selectedViewController)] );

Why did the debugger window lie? Specifically, does anyone know what value it displays as its address, and why the controllers would show the same address?

Best Answer

I have had this exact same problem, and I'm 90% sure it's related to building for a 2.1 (or possibly 2.X) SDK while using the 3.0 dev tools. In my case, setting the target SDK for 3.0 fixed this issue. Having your debugger essentially lie to you is frustrating ;)