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.

}

}

05-11 15:10