> For the complete documentation index, see [llms.txt](https://ios-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ios-course.cornellappdev.com/resources/tool-guides/xcode-project-setup.md).

# Xcode Project Setup

Fall 2023 | Vin Bui

{% hint style="info" %}
**Note that we will provide you with the setup in the assignments. However, this will be helpful for when you create a project on your own such as the Hack Challenge.**
{% endhint %}

### Create a New Project

1. Go to **File > New > Project**
2. Select the **iOS** tab, choose **App** and click Next
3. You can leave everything alone except for the following:
   1. Product Name: **Enter the name of the app**
   2. Interface: **Storyboard** (yes, keep Storyboard even though we won’t be using it)
   3. Language: **Swift**
   4. **Uncheck** “Use Core Data”
   5. **Uncheck** “Include Tests”

<figure><img src="https://1509678725-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lwk7443W4ukbAF9S07e%2Fuploads%2FWpxHnkM7S5KaVNhAlXe7%2FScreenshot%202023-06-04%20at%203.33.28%20PM.png?alt=media&amp;token=5fb74753-d14a-4ec0-bb06-cd1835fdc297" alt=""><figcaption></figcaption></figure>

4. Choose a directory for your project and hit **Create**

### **Switch to Programmatic Layout**

1. To utilize programmatic Auto Layout, delete `Main.storyboard` from the Navigator in Xcode. **Right click > Delete > Move to Trash**

<div><img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/18baf9ff-c6cd-467f-8041-e44fe6bfd024/Untitled.png" alt="Untitled"> <figure><img src="https://1509678725-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lwk7443W4ukbAF9S07e%2Fuploads%2FiSN2kmDt9cGpvyrr5B6X%2FUntitled.png?alt=media&amp;token=9b10643b-c175-411f-9d9f-e6c16df96e5f" alt="" width="267"><figcaption></figcaption></figure></div>

2. Press `CMD + SHIFT + F` or click on the 🔎 icon in the Navigator. Look up `storyboard` and you should see something like this:

<figure><img src="https://1509678725-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lwk7443W4ukbAF9S07e%2Fuploads%2F0suZgkxymVwaHifTAToz%2FUntitled.png?alt=media&amp;token=20f1c0aa-8a10-40d2-8962-44af1d411b8e" alt="" width="188"><figcaption></figcaption></figure>

3. Click on the <mark style="color:red;">red box above</mark> and look up `storyboard` in the filter search bar. Select `UIKit Main Storyboard File Base Name` and his **Backspace** on your keyboard to delete it.

<figure><img src="https://1509678725-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lwk7443W4ukbAF9S07e%2Fuploads%2FlNnp7TjEd1FWoGj4dafM%2FUntitled.png?alt=media&amp;token=8ef15391-09f8-406f-91eb-a58d9e2dda02" alt=""><figcaption></figcaption></figure>

4. Now select the <mark style="color:blue;">blue box</mark> from step 2, or go to `Info.plist` and delete `Storyboard Name` by clicking on the minus (-) symbol.

<figure><img src="https://1509678725-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lwk7443W4ukbAF9S07e%2Fuploads%2FTetyL3XvYBVqBHIXd2Dp%2FUntitled.png?alt=media&amp;token=a57eff72-2b7c-4abc-8489-dc162373b0a7" alt=""><figcaption></figcaption></figure>

### Setup `SceneDelegate.swift`

Add the following code to the function `scene` in `SceneDelegate.swift`

```swift
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // 1. Capture the scene
    guard let windowScene = (scene as? UIWindowScene) else { return }
    
    // 2. Create a new UIWindow and pass in a UIWindowScene
    let window = UIWindow(windowScene: windowScene)
    
    // 3. Create a view hierarchy programmatically
    let rootVC = ViewController()
    let navController = UINavigationController(rootViewController: rootVC)
    
    // 4. Set the navigation controller as the window's root view controller
    window.rootViewController = navController
    
    // 5. Set the window and call makeKeyAndVisible()
    self.window = window
    window.makeKeyAndVisible()
}
```
