1

In xcode 4.3.1, target iPad 5.1 simulator

  • create a single view app
  • use ARC, don't use Storyboard

  • in ViewController.h

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    {
            NSObject *anObject;
            NSObject *anotherObject;
    }
    
    -(void) makeObjects;
    
    @end
    
  • in ViewController.m add

    -(void) makeObjects{
            anObject = [[NSObject alloc] init];
            anotherObject = [[NSObject alloc] init];
    
            int a = 1;
    }
    
  • in AppDelegate.m add a line

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
    {
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            // Override point for customization after application launch.
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
            self.window.rootViewController = self.viewController;
    
            [self.viewController makeObjects]; // ADD THIS LINE  <--------
    
            [self.window makeKeyAndVisible];
            return YES;
    }
    
  • in ViewController.m, set a breakpoint at

    anObject = [[NSObject alloc] init];
    
  • run

  • step over breakpoint
  • anObject = 0x00000000, anotherObject is set!
rob mayoff
  • 375,296
  • 67
  • 796
  • 848

1 Answers1

1

Are you using the LLDB debugger? Currently it doesn't give you correct values on iVars in the simulator. Switch back to GDB and you'll find the correct values reported. I discovered this behavior here: UIViewController subclass can't assign instance variable.

And yes, I reported a bug. I got a response back from Apple stating it is a known issue.

Community
  • 1
  • 1
Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63