Reputation: 5
how do I import a swift file in another swift file so I could use variables. Here is my code from menuViewController.swift and I want to use variable selectedObject
import UIKit
class menuViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var selectedObject: String!
}
I want to use the variable from above file in ViewController.swift. Here is my ViewController.sswift
import UIKit
class ViewController: UIViewController, UIAlertViewDelegate {
}
Upvotes: 0
Views: 633
Reputation: 21003
If they are in the same target you do not need to import other Swift files.
import UIKit
class MenuViewController: UIViewController {
var selectedObject: String!
}
class ViewController: UIViewController {
let menuViewController = MenuViewController()
func doSomething() {
menuViewController.selectedObject = "foo"
}
}
The above is working fine for me.
Upvotes: 2
Reputation: 21
All you need todo is import the project. So say if your project is called my project, do:
import myproject
Upvotes: 1