I have a Bool firstAppear in my SecondViewController. When a video is played the Bool becomes false. Then if I go back to my FirstViewController and retu , the video plays again. As I understand I always create another instance of the ViewController so thats why my logic is false. What are the changes I need to make to achieve it ?
@IBAction func nextButtonPressed(sender: AnyObject) {
if let secondViewController = storyboard?.instantiateViewControllerWithIdentifier("answer") as? SecondViewController{
SecondViewController.id = self.id
}
self.navigationController?.pushViewController(secondViewController, animated: true)
}
And in Second:
private var firstAppear = true
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if firstAppear {
do {
try playVideo()
firstAppear = false
} catch AppError.InvalidResource(let name, let type) {
debugPrint("Could not find resource (name).(type)")
} catch {
debugPrint("Generic error")
}
}
}
