tags:

views:

1016

answers:

2

I have an class, and in the header I define this:

@interface MyViewController : UIViewController {
    BOOL blackBackground;
}
@property(nonatomic, assign) BOOL blackBackground;

In the implementation I have the @synthesize for blackBackground.

Then, I instantiate this object and do:

[myViewController setBlackBackground:YES];

now that boolean should have the value YES (or true ;) ). But then, I check:

if ([myViewController blackBackground]) {
NSLog(@"yep, it's true");
}

however, it doesn't seem to respond or return anything, either the value doesn't get set or I can't call/check it. Any idea what's wrong there?

+1  A: 

I think it is isBlackBackground or of course you can use self.blackBackground

quadelirus
meaning if (myViewController.blackBackground) { ...
quadelirus
+6  A: 

Are you sure you are actually using the above code? It has syntax errors and will not compile, so it is entirely possible you are not seeing that code executed because you are running old copies of the code.

The issue that you cannot declare a scalar property to have a any sort of retain,assign,copy semantic, it will result in a compile error. You should change:

@property(nonatomic, assign) BOOL blackBackground;

to

@property(nonatomic) BOOL blackBackground;
Louis Gerbarg
in fact it was a stupid typo in my code! Thanks! Strange thing is, I got it to work with @property(nonatomic, assign). what's the difference when I don't provide assign or retain (just nothing)? How do the created accessors look?
Thanks
retain means that the when you set the property you set it to the actual object (so your object will see mutations that occur), and bump the retain count. copy means your set the property to a copy of the object passed in. assign means you direct assignment (like in the retain) without increasing the retainCount. Since scalar values do not accept messages or participate in ObjC retain/release those attributes do not apply to them.
Louis Gerbarg