Question: I'm very new to Objective-C so sorry if this is extremely obvious to many of you, but I'm trying to work out how the following piece of code is actually working:

```
- (IBAction)chooseColour:(UIButton *)sender {
 sender.selected = !sender.isSelected;
}

```

Now it obviously toggles between the selected and unselected states of the button sending the action, but what is the code 'sender.selected = !sender.isSelected' actually saying? Is it just 'set the sender selected property to the opposite (i.e. ! not) of the getter'? So if the getter is 'getting' the current selected value as true then it sets the selected property as !true i.e false. Or is this a piece of convenience code that I'm not yet privy to? Because it also seems that '!sender.isSelected' simply means not selected as in 

```
if (!sender.isSelected){
statement
}

```

i.e. do statement if the sender is not selected. This is no doubt really obvious, just I'm a bit confused with it at the moment.

Thanks!

Answer: 
You are entirely correct, it's calling the getter to obtain the value and calling the setter with the NOT (`!`) of the value. It isn't Objective-C, it's plain C syntax.
> 
> Is it just 'set the sender selected property to the opposite (i.e. ! not) of the getter'?
> 
> 
> 

Exactly. That.

> 
> Or is this a piece of convenience code that I'm not yet privy to?
> 
> 
> 

No, the only piece of syntactic sugar is the dot notation for getters/setters, but you are already aware of it.