Pass variables from one ViewController to another in Swift

前端 未结 3 1301
一整个雨季
一整个雨季 2020-12-02 00:45

I have a calculator class, a first ViewController to insert the values and a second ViewController to show the result of the calculation. Unfortunately I get a error called

3条回答
  •  难免孤独
    2020-12-02 01:06

    In Swift, everything is public by default. Define your variables outside the classes:

    import UIKit
    
    var placesArray: NSMutableArray!
    
    class FirstViewController: UIViewController {
    //
    ..
    //
    }
    

    and then access it

    import UIKit
    
    class TableViewController: UITableViewController {
    //
    placesArray = [1, 2, 3]
    //
    }
    

提交回复
热议问题