I have set the ViewController() as a sharedInstance. When I try to fire a function from another view the shared function returns
fatal error: unexpectedly found nil while unwrapping an Optional value
I dont understand why is giving me an error using a sharedInstance and it works good if I call the function from inside the `ViewController'
class ViewController: UIViewController {
static let sharedInstance = ViewController()
@IBOutlet weak var playBtn: UIButton!
///
///
func audioPlayerIsNotPlaying() {
print("stop") //runs
playBtn.selected = false //fatal error: nil
playBtn.setImage(UIImage(named: "playBtn.png"), forState: UIControlState.Normal ) //fatal error: nil
}
}
Second View Controller:
ViewController.sharedInstance.audioPlayerIsNotPlaying()
Why is the playBtn button object is returning nil?