[Solved] Xcode unexpectedly found nil while unwrapping an Optional, but no idea why
Solved it. As the comments pointed out, the problem was that I was not accessing ViewController correctly. In order to access my ViewController outside of the ViewController class, I was creating a new instance of it by ViewController(). I solved it by putting the function inside the class and changing ViewController() part to self.ViewController. This … Read more