2

walrus operator of python language ( := )
work:- assign the value & also return that value.

language like swift at value assign it return nothing.
how to implement walrus operator kind a thing in swift language ?

I think it done by make function, pass address of variable & value.
assign value in that address & return value.
Is this work or any other way for this?

b m gevariya
  • 89
  • 1
  • 2
  • 9

1 Answers1

0

Joakim is correct.

Swift doesn't have a unary operator like C.

In C, you could do:

b = 10;
while (b>0) {
   print(b--);
}

In Swift, there isn't a unary ++ or -- operator, so you would do:

var b = 10
while (b > 0) {
   print b
   b -= 1
}

but, really, in Swift, you'd do this instead

for b in (0...10).reversed() { 
   print b
}

See Reverse Range in Swift

Michael Shulman
  • 383
  • 3
  • 6