At WWDC 2014, Apple announced a new direction with its innovative software programming language, named Swift, for future iOS and MacOS app development. The adoption of Swift has been phenomenal over the last 5+ years: open source language development, availability of an iPad Swift playground, language consistency, SwiftUI, and numerous features in Xcode, including SwiftUI preview, to support app development. This post details the steps to create a Swift 5 code-only (i.e., no storyboards) project within Xcode 11.
Getting Started: Creating the Code-only App
Create a new Xcode project using the ‘Single View Application‘ as the iOS template. Select ‘Swift‘ as the language. The other options include ‘Use Core Data‘, ‘Include Unit Tests‘, and ‘Include UI Tests‘.
There are two options for ‘User Interface‘ in Xcode 11: ‘SwiftUI‘and ‘Storyboard‘. If ‘SwiftUI‘ is selected, a main storyboard doesn’t exist, a ‘ContentView.swift‘ file is created instead to support SwiftUI code development, and the rest of this post doesn’t apply.
If ‘Storyboard‘ is selected, a ‘Main.storyboard‘ file and a ‘ViewController.swift‘ file are created. The rest of this post assumes that ‘Storyboard‘ was selected as the ‘User Interface‘.
Removal of Main.storyboard
Delete the file ‘Main.storyboard‘ from the ‘Project Navigator‘ pane.
Select the project in the ‘Project Navigator‘ pane, then select the target in the middle editor pane, and finally, click on the ‘General‘ tab). Clear the ‘Main Interface‘ field.
Select the ‘Info.plist‘ file in the ‘Project Navigator‘ pane. Expand the ‘Application Scene Manifest‘ line in the editor pane as shown and remove the line titled ‘Storyboard Name‘. At this point, all evidence of a main storyboard are gone.
Upon creation of the Swift 5 project within Xcode 11, a new file ‘SceneDelegate.swift‘ in iOS 13 was created along with the expected ‘ViewController.swift‘ file. Both of these files require some edits to support a code-only Swift 5 iOS 13 app in Xcode 11.
Compile and Run
At this point, the project should not show any errors or warnings and should compile. Select a device or simulated device, as appropriate, and compile/run. The app should launch and, in this case, display a blue background. This makes an easy way to establish a starting point to develop a code-only app.
Xcode 11 – Create a New Project – No Storyboard video by Sean Allen.
The Xcode and Swift logos are copyrights and trademarks of Apple.