Swift make method parameter mutable?

后端 未结 7 848
滥情空心
滥情空心 2020-12-07 17:04

How can I deal with this error without creating additional variable?

func reduceToZero(x:Int) -> Int {
    while (x != 0) {
        x = x-1            //         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 17:54

    There are some cases where we dont ned to use inout

    We can use something like this if you want that changes/scope to be only inside the function:

    func manipulateData(a: Int) -> Int {
        var a = a
        // ...
    }
    

提交回复
热议问题