.h
@property (nonatomic,assign) BOOL dontSendDelegate;
.m
@synthesize dontSendDelegate;
- (id) initWithSession:(AVCaptureSession *)aSession outputFileURL:(NSURL
*)anOutputFileURL
{
self = [super init];
if (self != nil)
{
self.dontSendDelegate = NO;
}
return self;
}
if (self.dontSendDelegate == YES)
{
NSLog(@"YES");
}
else
{
NSLog(@"NO");
}
Thats all my code in that class relating to the BOOL.
It always prints YES.
What is it that I’m not understanding? I expect it to always print NO.
EDIT
Used Xcode to search ‘dontSendDelegate’
It only appears in the code I’ve shown. Which is copy and paste.
Changed it to an int and assigned 0 instead of the ‘NO’ and did the comparison == 1 instead of == YES and it works as you would expect. But I’m still lost as to why BOOL was not working.
Thanks for all the help and discussion about the problem.
When you put the mutable part of an expression (your bool instance variable) before a comparison operator such as ==, sometimes you have a typo where you write = instead, so you set the variable instead of compare it. Look for errors of this type.
Or always put the immutable value first, so in the code you have provided so far you would instead write
That way, if you ever type one equal sign instead of two, the compiler will complain.
(from comments) When testing boolean variables, you don’t need to use == at all. Just use
if (self.dontSendDelegate)orif (!self.dontSendDelegate).