I have a ViewController file called TwoViewController.swift and a nib file called TwoViewController.xib.
TwoViewController.swift like this ↓
class TwoViewController: UIViewController {
var pageTitle: String?
・・・・・・
override func viewDidLoad() {
super.viewDidLoad()
}
・・・・・・
}
then, I would new a TwoViewController and present it at OneViewController.swift like this↓
class OneViewController: UIViewController {
・・・・・・
override func viewDidLoad() {
super.viewDidLoad()
}
・・・・・・
func presentTwo() {
let two = new TwoViewController()
two.pageTitle = "2222"
self.present(two, animated: false, completion: nil)
}
}
But, I want to new TwoViewController and set value to property pageTitle at the same time like this ↓
new TwoViewController(pageTitle: "22222")
To do that, I think I need create an init method at TwoViewController. I tried to make an init method like below↓. Is this correct?
class TwoViewController: UIViewController {
var pageTitle: String
init(pageTitle: String) {
super.init(nibName: nil, bundle: nil)
self.pageTitle = pageTitle
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
・・・・・・
}