8 Replies Latest reply: May 13, 2011 3:29 PM by xnav
Chap Harrison Level 1 Level 1 (115 points)

I hate asking questions like this.


I set a breakpoint in an IBAction method 'pushed:' inside FooViewController.  At runtime I pressed a GUI button and processing stopped in pushed:.


In the data-viewing pane of xcode, I see



self = (FooViewController *) 0x... etc.



Indented under this is



UIViewController = (UIViewController) { ...



Nowhere do I see any of my instance variables!!


Now, they were synthesized from properties, but that doesn't matter, does it?


The code that proceeds to set some instance variables runs fine.


Why isn't xcode displaying self's instance vars?




  • xnav Level 5 Level 5 (6,635 points)

    In the Debugger Nav window (Xcode4) or Debug window (Xcode3) use the caret next to 'self' to expand the list of ivars.

  • Chap Harrison Level 1 Level 1 (115 points)

    Unless I misunderstand what you're referring to by the "Debugger Nav" window (see below), that's exactly what I did - and it only shows UIViewController.



  • xnav Level 5 Level 5 (6,635 points)

    It appears as if you really don't have any ivars!  Let's see your .h.

    One ivar 'crash' here:


  • Chap Harrison Level 1 Level 1 (115 points)

    Yes, yours looks like I was expecting mine to look.


    Note that viewDidLoad (below) does work correctly, producing the expected results in the simulator!




    @interface Hangman3ViewController : UIViewController {




    @property (         nonatomic )           NSInteger  wordLength;

    @property ( retain, nonatomic )           NSString  *alphabet;

    @property (         nonatomic )           unichar    guess;

    @property (         nonatomic )           NSInteger  guessNo;

    @property ( retain, nonatomic )           NSMutableString *board;


    @property ( retain, nonatomic ) IBOutlet  UILabel   *boardLabel;

    @property ( retain, nonatomic ) IBOutlet  UILabel   *guessNumberLabel;

    @property ( retain, nonatomic ) IBOutlet  NSArray   *keyboardButtons;


    - (IBAction)letter:(id)sender;

    - (void)showBoard;



    and, Hangman3ViewController.m:


    #import "Hangman3ViewController.h"


    @implementation Hangman3ViewController


    @synthesize wordLength       = _wordLength// preprocessor command to gen getter/setter and instance variable

    @synthesize boardLabel       = _boardLabel// preprocessor command to gen getter/setter and instance variable

    @synthesize guessNumberLabel = _guessNumberLabel// Guess #n

    @synthesize keyboardButtons  = _keyboardButtons;   // array of buttons

    @synthesize alphabet         = _alphabet;    // A-Z unichars

    @synthesize guess            = _guess;       // unichar

    @synthesize guessNo          = _guessNo;     // int

    @synthesize board            = _board;


    - (IBAction)letter:(id)sender



                Get letter from sender - driven when key button is pressed.


                The button's tag is an int from 0-25, identifying what letter of the alphabet it is.

                Extract that unichar from ALPHABET as 'guess'.  Then, disable the button,

                which has been defined to have its text turn white (invisible) when disabled.



        UIButton *button = (UIButton *)sender;

        self.guess = [self.alphabet characterAtIndex: button.tag];

        NSLog(@"Received keystroke: %C", self.guess);

        [button setEnabled:NO];



    - (void)showBoard



        self.boardLabel.text = self.board;

        self.guessNumberLabel.text = [NSString stringWithFormat:@"Guess #%d", self.guessNo];



    - (void)dealloc


        [_boardLabel release];

        [_guessNumberLabel release];

        [_keyboardButtons release];

        [super dealloc];



    - (void)didReceiveMemoryWarning


        // Releases the view if it doesn't have a superview.

        [super didReceiveMemoryWarning];


        // Release any cached data, images, etc that aren't in use.



    #pragma mark - View lifecycle


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

    - (void)viewDidLoad


        NSLog(@"Hello from viewDidLoad");

        [super viewDidLoad];

        self.alphabet   = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // unichar string

        self.wordLength = 7// temp - will be set from flipside later on

        self.guessNo    = 1;

        [self.board setString:@"_______"]; // actually dynamic based on wordLength

        self.board = @"_______";

        [self showBoard];



    - (void)viewDidUnload


        [super viewDidUnload];

        // Release any retained subviews of the main view.

        // e.g. self.myOutlet = nil;



    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation


        // Return YES for supported orientations

        return (interfaceOrientation == UIInterfaceOrientationPortrait);




  • xnav Level 5 Level 5 (6,635 points)

    Try doing it like this:

    #import <UIKit/UIKit.h>
    @interface CrashViewController : UIViewController {
                        IBOutlet UITextField *crash;
    @property (nonatomic, retain)  UITextField *crash;
  • xnav Level 5 Level 5 (6,635 points)

    If you don't change your header then in the debug variable area right click on 'self' and select "Add Expression", then enter e.g.' _wordLength' and the ivar will be displayed.

  • Chap Harrison Level 1 Level 1 (115 points)

    Okay, I inserted foobar as follows:


    @interface Hangman3ViewController : UIViewController {

        NSString *foobar;




    And sure enough, foobar now appears in the debugger.


    Thank you.  I'll stop trying to expect xcode to behave like a professional tool :-/

  • xnav Level 5 Level 5 (6,635 points)

    That's just the way it is with dynamic ivars, they like to be hidden!  I never use them since I started Obj-C coding before they were dreamed up.