This seems so easy, I’m embarrassed. Every time I trigger this it just stays in the “On” state. it doesn’t ever pass the conditional to turn off.
-(void) lightbulbSwapImages
{
NSImage *bulbOn = [NSImage imageNamed: @"sidebar_lightbulb_on.png"];
NSImage *bulbOff = [NSImage imageNamed: @"sidebar_lightbulb_off.png"];
if (lightbulb.image = bulbOff)
[self.lightbulb setImage: bulbOn];
else
[self.lightbulb setImage: bulbOff];
}
Change
=with==.Reason behind your issue:
What you are doing is, trying to assign
bulbOfftolightbulb.imageand the result you are checking as a condition which will always returntrueiflightbulb.imageis not nil. Due to this it will never execute your else part.It is equivalent to,
On a side note, if you are using
@propertyforlightbulb, make it consistent by using the same everywhere including the if condition. In my answer, I have changed fromlightbulb.imagetoself.lightbulb.image.