How does Xcode load the main storyboard?

后端 未结 7 1235
遥遥无期
遥遥无期 2020-12-13 08:37

When I create a new single view application in Xcode 4.6 using storyboard, we can see that the main function creates a new application using the application delegate like th

7条回答
  •  鱼传尺愫
    2020-12-13 08:46

    Bit late to the party but you can get to the viewController from the window as shown below

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
        func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
            var viewController = window?.rootViewController as? ViewController
            if let viewController = viewController {
                // do awesome stuff
            }
    
            return true
        }
    }
    

提交回复
热议问题