Is it possible to run a View Controller method within the App Delegate?
I am trying to make a static Quick Action that runs a View Controller Method whose purpose is to perform mathematical calculations, and output the results onto UILabels. In other words the Quick Action takes the place of user input and automatically passes a value to the View Controller method, which in turn updates corresponding Labels in the UI.
It's a single view application.
Over at stackoverflow I found a solution that allows me to get apparently verify that the current view is of the proper class and then creates an instance of that class. Xcode throws an exception when running the function: unexpectedly found nil while unwrapping an Optional value.
Here's slightly a slightly edited version of that code:
if let view = self.window {
vc = view.rootViewController!
if(vc is ViewController){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController;
viewController.calculate("5");
print("Method Done!")
}
}And here's the method it's trying to access in View Controller:
func calculations(input: String){
inputTextField.text! = "#" +input;
Labe1l.text = printResult1(Double(input)!);
Label2.text = printResult2(Double(input)!);
Label3.text = printResult3(Double(input)!);
Label4.text = printResult4(Double(input)!);
Label5.text = printResult5(Double(input)!);
Label6.text = printResult6(Double(input)!);
}So I'm guessing that either: A) What I'm hoping for isn't possible or B) I have no idea what I'm doing