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.
from documentation : 

```
@property(nonatomic,getter=isSelected) BOOL selected;                                // default is NO may be used by some subclasses or by application

```

//explanation
if you use ![sender isSelected] value in property isn't changed. then if you use setter sender.selected = ![sender isSelected] - new value is set to the sender (selected property). then run getter sender isSelected return new value, uff i hope it helps