I need a function from global scope change a label on the storyboard.
When I try running this code, the error I get is:
fatal error: unexpectedly found nil while unwrapping an Optional value
The problem is that viewController.congratulations is null.
How to fix that? Thanks in advance!
func myAlert ()
{
// how to change 'configuration.text' from here?
let storyboard = UIStoryboard(name: "Main", bundle: nil);
let viewController : ViewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController;
viewController.congratulations.text = "test";
}
class ViewController: UIViewController
{
@IBOutlet weak var congratulations: UILabel!;
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myAlert();
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}