Home > Back-end >  Why does “=“ work but “ ” gives a warning (Swift)
Why does “=“ work but “ ” gives a warning (Swift)

Time:12-28

I am confused as to why “=“ successfully changes the variable but “ ” does not and brings back a warning. I would also like to know how to make “ ” work. What I see

CodePudding user response:

I think you might be looking for a compound assignment operator like =.

  • score = 10 makes sense: it’s a statement which sets the score to 10
  • score = 10 also makes sense: it’s a statement which increases score by 10
  • but score 10 does not: it’s an expression which just evaluates to an unused result.
  • Related