Swift make method parameter mutable?

后端 未结 7 804
滥情空心
滥情空心 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 18:01

    Swift3 answer for passing mutable array pointer.

    Function:

    func foo(array: inout Array<Int>) {
        array.append(1)
    }
    

    Call to function:

    var a = Array<Int>()
    foo(array:&a)
    
    0 讨论(0)
提交回复
热议问题