Swift: how does the application delegate get a link to the view controller?

I started a new Swift project, I play with things to see how wiring works with downstream versions since I have never used them before.

A project is a single-view application using the default storyboard created by Xcode 6.1. It generates the classes AppDelegate.swift and ViewController.swift, as well as Main.storyboard.

Btw, I kind of left this lesson:

http://www.raywenderlich.com/74904/swift-tutorial-part-2-simple-ios-app

I have a button work and several textview controls that I added using the storyboard interface designer.

What I would like to do now, connect the didFinishLaunching application delegation application to the view controller.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { } 

I found many StackOverflow articles discussing this, however all examples create an instance of your own view controller. I just want to get a link to the view controller that was launched through the storyboard.

What is the best way to do this? Feel free to tell me the relevant documents or other messages.

+6
source share
1 answer

I finally found this article on checking the current view controller , which contained the logic I was looking for:

 var myViewController : ViewController! ... if let viewControllers = self.window?.rootViewController?.childViewControllers { for viewController in viewControllers { if viewController.isKindOfClass(ViewController) { myViewController = viewController as ViewController println("Found the view controller") } } } 
+7
source

Source: https://habr.com/ru/post/982859/