0
var a:Bool
var b:Bool
var c:Bool = true

a = !c

a = b = !c

In the above example a = !c works fine, while the a = b = !c gives compile time error.

Is this simple syntax not supported in Swift 3.0? What could be a better way for this line of code.

NNikN
  • 3,720
  • 6
  • 44
  • 86
  • The gist of it is "the assignment operator in Swift does not itself return a value" – brw59 Jul 24 '17 at 03:42
  • If you're desperate to do the assignment on one line, you could use tuple syntax, but you'd still have to specifically assign each value: (a, b, c) = (true, true, true) – yogesh wadhwa Jul 24 '17 at 04:47
  • For the joy of it, an obscure alternative approach would be: `b = (a = !c, a).1`. – dfrib Jul 24 '17 at 07:38

0 Answers0