I want to pass string data from parent vc to child vc in swift 3.
My child vc is container view. So watch my code:
class ParentViewController: UIViewController
@IBOutlet var continerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let vc = storyboard?.instantiateViewController(withIdentifier: "ChildVCID") as! ChildViewController!
vc?.myStr = "Hello Bro"
addChildViewController(vc!)
continerView.addSubview((vc?.view)!)
didMove(toParentViewController: vc)
}
}
And my child code is:
class ChildViewController: UIViewController
var myStr:String!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
print("Str is: ",myStr)
}
Therefore how to fix this?