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.

    }

 

 

}

 

相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2021-10-03
  • 2021-12-26
  • 2021-12-21
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-10-12
  • 2021-09-07
相关资源
相似解决方案