Instantiate and Present a viewController in Swift

前端 未结 16 1719
难免孤独
难免孤独 2020-11-22 13:04

Issue

I started taking a look of the new Swift on Xcode 6, and I tried some demo projects and tutorials. Now I am stuck at:

16条回答
  •  独厮守ぢ
    2020-11-22 13:14

    I know it's an old thread, but I think the current solution (using hardcoded string identifier for given view controller) is very prone to errors.

    I've created a build time script (which you can access here), which will create a compiler safe way for accessing and instantiating view controllers from all storyboard within the given project.

    For example, view controller named vc1 in Main.storyboard will be instantiated like so:

    let vc: UIViewController = R.storyboard.Main.vc1^  // where the '^' character initialize the controller
    

提交回复
热议问题