When to use inout parameters?

前端 未结 7 1603
情书的邮戳
情书的邮戳 2020-12-13 03:15

When passing a class or primitive type into a function, any change made in the function to the parameter will be reflected outside of the class. This is basically the same t

7条回答
  •  爱一瞬间的悲伤
    2020-12-13 04:09

    when use inout parameter swift 4.0 Work

    class ViewController: UIViewController {
    
        var total:Int = 100
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.paramTotal(total1: &total)
        }
    
        func paramTotal(total1 :inout Int) {
            total1 = 111
            print("Total1 ==> \(total1)")
            print("Total ==> \(total)")
        }
    }
    

提交回复
热议问题