How do I fix this? I'm a new coder. Thank you
I get the follow error:
"Cannot assign to immutable expression of type 'Bool'"
When I try to set the "isSelected" to false
and true
@IBAction func onFilter(_ sender: Any) {
if ((sender as AnyObject).isSelected == true) {
hideSecondaryMenu()
(sender as AnyObject).isSelected = false
} else {
showSecondaryMenu()
(sender as AnyObject).isSelected = true
}
}
You are getting this error because when you are converting sender to
AnyObject
you are gettingimmutable
type object so you cannot update its properties, The best option to solved your problem is to change your sender declaration fromAny
to actualUIControl
means if it is button thenUIButton
.If you want to still use
Any
then convert sender to actualUIControl
that it is belong to.