inout

What does an ampersand (&) mean in the Swift language?

北慕城南 提交于 2019-11-26 13:00:55
问题 I know about the ampersand as a bit operation but sometimes I see it in front of variable names. What does putting an & in front of variables do? 回答1: It works as an inout to make the variable an in-out parameter. In-out means in fact passing value by reference, not by value. And it requires not only to accept value by reference, by also to pass it by reference, so pass it with & - foo(&myVar) instead of just foo(myVar) As you see you can use that in error handing in Swift where you have to