Reputation: 36070
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:
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:
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:
and I get the same problem:
Upvotes: 1
Views: 435
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
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