swift -- 静态变量static


import UIKit

 

class ViewController: UIViewController {

 

    //静态变量  swift中的static静态变量,只能在这里声明,不能在方法中声明,会报错

    static var i : Int = 1

    

 

    override func viewDidLoad() {

        super.viewDidLoad()

        

        //调用静态变量

//        print(self.i)  错

          print(ViewController.i)     //这样调用

        

        

        // Do any additional setup after loading the view, typically from a nib.

    }

 

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

 

 

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM