0

I am trying to set a BOOL within Xcode and for some reason it is plain refusing to work. Nothing else is setting this bool, just this one instance. My code is below:

.h

@interface SuspectsViewController : UIViewController 
{
    BOOL boolContentChanged;
}

@property (nonatomic) BOOL boolContentChanged;

.m

@synthesize boolContentChanged;

-(IBAction)buttonPressed:(id)sender
{
    boolContentChanged = true;
}

I have also tried using self.boolContentChanged but nothing happens either. To try and debug this I used po boolContentChanged and get the following output, the first po is before boolContentChanged = true and the second is after.

(lldb) po boolContentChanged
(BOOL) $4 = '\0' <nil>
(lldb) po boolContentChanged
(BOOL) $7 = '\0' <nil>

Does the $ indicate that it's pointing to a certain address, or is that purely for debugging reference?

Also, is there any reason this would be nil? Surely it doesn't need implicitly setting if it is a bool and not a pointer?

Any advice on this is much appreciated as I can't work it out, Thanks in advanced, Elliott

Elliott D'Alvarez
  • 1,217
  • 16
  • 30
  • 3
    Objective-C uses `YES` and `NO` boolean literals, not `true` and `false`. Not sure that will help... – trojanfoe Apr 10 '12 at 10:00
  • 3
    The snippet from your .h file is ambiguous. I suspect you have got both an instance variable (synthesized for you) and a global variable with the same name and you are referencing a different one in different contexts. Please show the exact code. – Ken Thomases Apr 10 '12 at 11:36
  • Hi all, I used to have it as bool = true, rather than BOOL but there really shouldn't be any difference in terms of definition, will give it a shot anyway. And unfortunately my code is about 500 lines long, but it definitely doesn't have a global variable with the same name. That's why I'm getting so confused by the matter. It would normally show up as a warning if this occurred anyway would it not? – Elliott D'Alvarez Apr 10 '12 at 17:45
  • Let me re-ask in a different way: is the `BOOL boolContentChanged;` from your snippet above within curly braces of your `@interface`? Like `@interface MyClass : SuperClass { BOOL boolContentChanged; /* other ivars */ } /* methods */ @end`? – Ken Thomases Apr 11 '12 at 07:00
  • Hi Ken, Yes it appears in the '@interface SuspectsViewController : UIViewController { BOOL boolContentChanged;}' then '@property (nonatomic) BOOL boolContentChanged;' It is then synthesised in the .m and accessed like mentioned above using 'boolContentChanged = true'. There is no other reference to it, and there are no other variables with the same name. I'm a bit confused, I think I had this issue before but can't remember why... – Elliott D'Alvarez Apr 11 '12 at 15:06

3 Answers3

8

"po" in the debugger (gdb) is short for "print-object". The BOOL type is not an Objective-C object. Use "p" or "print" to display the value of BOOL, int, char, etc.

The dollar-number ("$4") output by the debugger in response to your "po" command is assigning the result to a variable in the debugger which you can use in later commands.

As to the problem you describe, can you confirm that your action method is actually getting invoked? Try adding:

NSLog( @"In %@", NSStringFromSelector( _cmd ));

to your -buttonPressed method. If your action is actually getting invoked, you'll see this in the debugger:

In buttonPressed:

You can also have the NSLog() output the values of your BOOL:

NSLog( @"Before: %d", (int)boolContentChanged );
more tension
  • 3,312
  • 17
  • 19
  • Thanks for the reply and information about po / p, only recently came in to contact with it all and presumed it was used for everything. I can confirm the method is being invoked, otherwise my breakpoints where I was using po would have never been hit. I can also confirm using NSLog that the bool isn't changing for some reason, I wish I could work out why. I am on another computer at the moment and waiting for my repository to pull, then I will submit some more debug outputs to my post above. Thanks once again for the help! – Elliott D'Alvarez Apr 13 '12 at 08:42
0

I finally managed to figure out what was happening. In regards to the debugger it did make a practical difference using YES / NO as opposed to true / false, the values were still being set if I used p to explicitly find them, but when using YES / NO they would show automatically. So once again it seems to be the intellisense that is failing to update in certain situations.

Thanks for the help all.

Elliott D'Alvarez
  • 1,217
  • 16
  • 30
-2

When you use BOOL you need to use YES or NO not true and false.

TegRa
  • 519
  • 3
  • 10