&& in if statement (swift)

    @IBAction func cycanButtonAction(_ sender: Any) {
        if ((anzeigeZahl.backgroundColor == UIColor.cyan) && FarbeOderZahl = false) {
        score += 1
            routine()
           
        }

        else {
           youLostButton.isHidden = false
           routine()
        }
    }



in line 2 it says: "cannot assign to value && returns immutable value"


how can I fix it?

thanks!

Single equal sign `=` is an assignment operator and I guess you misplaced it with `==` in line 2.


And generally, when expression is a `Bool` (not `Bool?`), better use `!expression` than `expression == false`.

And generally, when expression is a

Bool
(not
Bool?
), better use
!expression
than
expression == false
.

Indeed. In Swift it reads badly but will typically work. In C-based languages it’s not guaranteed to work, that is, there are Boolean expressions where

!expression
and
expression == false
yield different results!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
&& in if statement (swift)
 
 
Q