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