Xcode 11.2.1: Switching Storyboards – A Common Hurdle
Many developers encounter a frustration in Xcode: wanting to use a different storyboard than the default "Main" storyboard, only to find they can't make the switch. If you're facing this issue in Xcode 11.2.1 using Swift 5, this article is for you!
The Scenario:
You've created a new project in Xcode. You're ready to design your application's user interface, but you want to start with a different storyboard. You've diligently created a new storyboard named "Start" and are eager to make it the main entry point for your app. However, Xcode stubbornly refuses to let you change the "Main" storyboard in the project settings.
The Original Code (or Lack Thereof):
This isn't a code issue, but a setting configuration problem. Typically, you'd expect to find an option in Xcode's project settings to specify which storyboard acts as the entry point for your application.
Understanding the Issue:
The crux of the problem lies in how Xcode manages the initial view controller setup. In earlier versions, Xcode had a more direct way to define the main storyboard. However, with Xcode 11.2.1, the process has been streamlined. The "Main" storyboard is automatically associated with the initial view controller, making it appear fixed even though it's not.
Resolving the Issue:
-
Deleting the 'Main' storyboard: The most direct solution is to delete the "Main" storyboard altogether. This will trigger Xcode to prompt you for a new storyboard when you run the project. Select your newly created "Start" storyboard, and you'll have successfully switched your main storyboard.
-
Adding a launch screen: Another way to achieve this is to add a launch screen storyboard, which is distinct from your application's main storyboard. Follow these steps:
- In Xcode's Project Navigator, select your project.
- Under "Interface" in the project settings, check the box for "Launch Screen File".
- A new "LaunchScreen.storyboard" will be created.
- In the "Main Interface" field, select your "Start" storyboard.
Additional Insights:
- Best practices: It's usually recommended to have a separate launch screen storyboard for a more polished user experience.
- Xcode's "Main" storyboard: While the "Main" storyboard is a default, it's not inherently necessary. You have complete control over the initial view controller used in your app.
- SwiftUI: If you are exploring SwiftUI, it's important to note that the storyboard mechanism becomes less relevant as SwiftUI relies on a different approach to building user interfaces.
Conclusion:
Switching your main storyboard in Xcode 11.2.1 might appear tricky, but the solution is simple and straightforward. By understanding the default behavior and how Xcode manages initial view controllers, you can easily adapt your project to use your preferred storyboard.
Remember, Xcode provides flexibility in how you structure your app. Explore the available options and choose the method that best suits your needs.