Tono Nam
Tono Nam

Reputation: 36070

BOOL variable behaves like it is NO when it actually is YES iPhone

I am new to objective-c and it seems to be very strange. I don't want to enable a method if a BOOL variable named "isFirstWordBeingAnimated" is equal to YES.

the variable isFirstWordBeingAnimated is equal to NO and for some reason it is treated as YES: enter image description here

note that when I place the mouse on top of that variable meanwhile debugging xcode tells me that isFirstWordBeingAnimated is equal to NO. Why is it that the returns block gets executed !?

Moreover, I have set isFirstWordBeingAnimated=YES only on once of my code with a breackpoint: enter image description here

I have not reached that breakpoint and xCode thinks it is equal to YES and I set that variable equal to NO when the view did loaded. Why is this?

Could it be because I have not defined the getters and setters? I defined isFirstWordBeingAnimated at the top of my .m file without creating the mutator (setter) and accessor (getter) methods...


EDIT

I have changed my code:

enter image description here

enter image description here

and I get the same problem:

enter image description here

Upvotes: 1

Views: 435

Answers (2)

Fabio Poloni
Fabio Poloni

Reputation: 8371

First I would create a property in your header-file:

@property (nonatomic, assign, getter= isFirstWordBeingAnimated) BOOL firstWordBeingAnimated;

Also add to your main-file:

@synthesize firstWordBeingAnimated;

Next I don't like to use if(isEnabled) return;

Better you put brackets around return;

if (isEnabled) {
     return;
}

Try if (isEnbabled) instead of if (isEnabled==YES), I won't change anything, but I have no other ideas.

Upvotes: 1

sudo rm -rf
sudo rm -rf

Reputation: 29524

First of all, no need to use isFirstWordBeingAnimated == YES. Just stick the boolean in the parentheses and it will be evaluated for true or false. Secondly, you created the getter/setter fine but you're not actually using it. If you wanted to refer to the boolean or set it, use self.isFirstWordBeingAnimated.

On your problem, though, a boolean is always false unless you explicitly set it to true. In your case I believe the problem lies in the fact that your boolean is never created - thus making it false. If you wouldn't mind more code would help to understand exactly what you're doing.

Upvotes: 0

Related Questions