Inside my viewDidLoad I have the following. But I cannot seem to get the syntax right.
[led.highlighted: [[NSUserDefaults standardUserDefaults] boolForKey:@"led"]];
and I also tried
[led.highlighted setValue:[[NSUserDefaults standardUserDefaults] boolForKey:@"led"]];
but that one errors with “Bad Receiver type ‘BOOL'”
My method that sets the value from an IBAction seems to be OK.
[[NSUserDefaults standardUserDefaults] setBool:led.isHighlighted forKey:@"led"];
So how exactly do I return the value of led.highlighted?
led.highlightedaccesses the property; depending on it being on the right- or left-hand side of a statement, it uses the getter or the setter, respectively.This assumes that you haven’t changed the getter and setter names to
isHighlightedandsetIsHighlighted:Given that, to set the property you can do either:
or
Your first attempt,
[led.highlighted:...]is just incorrect syntax. The second,[led.highlighted setValue:...]uses the accessor to gethighlighted, which is aBOOL, and then tries to send a message to it.BOOLs aren’t objects, so you can’t send messages to them.