Bird
Raised Fist0
iOS Swiftmobile~20 mins

Creating a new iOS project in iOS Swift - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
iOS Project Creator
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What is the initial UI shown when you create a new SwiftUI iOS project?
After creating a new SwiftUI iOS project in Xcode, what does the default ContentView display on the screen?
iOS Swift
import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
    }
}
AA screen showing the text "Hello, world!" centered with padding
BA blank white screen with no text
CA screen showing a button labeled "Click me"
DA screen showing an image placeholder
Attempts:
2 left
💡 Hint
Think about the default text SwiftUI uses to greet you.
❓ lifecycle
intermediate
2:00remaining
What is the role of the @main struct in a new SwiftUI iOS project?
In a new SwiftUI iOS project, what does the struct marked with @main do?
iOS Swift
import SwiftUI

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
AIt manages the app’s network connections
BIt is a placeholder and has no effect
CIt defines the app’s background tasks only
DIt defines the app’s entry point and main scene for the UI
Attempts:
2 left
💡 Hint
This struct tells the system where the app starts running.
📝 Syntax
advanced
2:00remaining
What error occurs if you forget to add a body property in the ContentView struct?
Consider this code snippet for ContentView: struct ContentView: View { // body property is missing } What error will Xcode show?
iOS Swift
struct ContentView: View {
    // Missing body property
}
ANo errors, compiles fine
BType 'ContentView' does not conform to protocol 'View'
CMissing return in function
DUnexpected token 'struct'
Attempts:
2 left
💡 Hint
The View protocol requires a body property.
❓ navigation
advanced
2:00remaining
How do you add a navigation bar title in a new SwiftUI project?
Given this ContentView, how do you add a navigation bar title "Home"? struct ContentView: View { var body: some View { Text("Welcome") } }
iOS Swift
struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("Welcome")
                .navigationTitle("Home")
        }
    }
}
AWrap Text in NavigationView and add .navigationTitle("Home") modifier
BAdd .title("Home") modifier directly to Text
CUse .navigationBarTitle("Home") on Text without NavigationView
DSet title in App struct instead of ContentView
Attempts:
2 left
💡 Hint
Navigation titles require a NavigationView container.
🧠 Conceptual
expert
3:00remaining
Why does a new SwiftUI project use WindowGroup in the App struct?
What is the purpose of using WindowGroup in the @main App struct of a new SwiftUI iOS project?
iOS Swift
import SwiftUI

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
AIt is a legacy container replaced by NavigationView
BIt is used to create modal dialogs
CIt manages multiple windows and scenes for the app, supporting multitasking
DIt only works on macOS and has no effect on iOS
Attempts:
2 left
💡 Hint
Think about how iPad apps can have multiple windows.

Practice

(1/5)
1. What is the first step when creating a new iOS project in Xcode?
easy
A. Write Swift code immediately.
B. Open Xcode and select 'Create a new Xcode project'.
C. Download an app template from the App Store.
D. Connect your iPhone to the computer.

Solution

  1. Step 1: Open Xcode

    You must start by opening Xcode, the tool used to build iOS apps.
  2. Step 2: Choose to create a new project

    Selecting 'Create a new Xcode project' starts the setup wizard for your app.
  3. Final Answer:

    Open Xcode and select 'Create a new Xcode project'. -> Option B
  4. Quick Check:

    First step = Open Xcode and create new project [OK]
Hint: Always start by opening Xcode and creating a new project [OK]
Common Mistakes:
  • Trying to write code before creating a project
  • Downloading unrelated templates
  • Connecting device before project setup
2. Which option correctly describes the interface style choices when creating a new iOS project?
easy
A. SwiftUI or Storyboard
B. UIKit or JavaFX
C. React Native or Flutter
D. XML or JSON

Solution

  1. Step 1: Understand interface styles in Xcode

    Xcode offers SwiftUI and Storyboard as main interface design options for iOS apps.
  2. Step 2: Identify correct pair

    SwiftUI is the modern declarative UI framework, Storyboard is the visual layout tool.
  3. Final Answer:

    SwiftUI or Storyboard -> Option A
  4. Quick Check:

    Interface style = SwiftUI or Storyboard [OK]
Hint: Remember: SwiftUI and Storyboard are Xcode's UI options [OK]
Common Mistakes:
  • Confusing with unrelated frameworks like React Native
  • Mixing UI frameworks from other platforms
  • Choosing data formats instead of UI styles
3. After filling in the app name as "MyApp" and selecting SwiftUI, what will Xcode create?
medium
A. A Storyboard file without SwiftUI code
B. Only a blank text file named MyApp.txt
C. An Android app project
D. A project folder with SwiftUI files and a default ContentView.swift

Solution

  1. Step 1: Understand project creation with SwiftUI

    Choosing SwiftUI creates a project folder containing SwiftUI code files.
  2. Step 2: Identify default files

    Xcode generates ContentView.swift as the default UI file for SwiftUI projects.
  3. Final Answer:

    A project folder with SwiftUI files and a default ContentView.swift -> Option D
  4. Quick Check:

    SwiftUI project creates ContentView.swift file [OK]
Hint: SwiftUI projects always include ContentView.swift by default [OK]
Common Mistakes:
  • Expecting unrelated file types
  • Confusing iOS with Android projects
  • Assuming Storyboard files appear with SwiftUI
4. You created a new project but forgot to select SwiftUI and chose Storyboard instead. What issue might you face?
medium
A. The app will crash immediately on launch.
B. Xcode will refuse to build the project.
C. Your UI code will use Storyboard files, not SwiftUI syntax.
D. You cannot add any UI elements later.

Solution

  1. Step 1: Recognize interface style impact

    Choosing Storyboard means your UI is designed with Storyboard files, not SwiftUI code.
  2. Step 2: Understand consequences

    This affects how you write UI code; you must use UIKit and Storyboard methods.
  3. Final Answer:

    Your UI code will use Storyboard files, not SwiftUI syntax. -> Option C
  4. Quick Check:

    Storyboard choice means no SwiftUI code [OK]
Hint: Storyboard projects use visual UI files, not SwiftUI code [OK]
Common Mistakes:
  • Thinking the app will crash immediately
  • Believing Xcode blocks building
  • Assuming UI elements cannot be added later
5. You want to create an iOS app that supports both SwiftUI and UIKit views. How should you start your new project?
hard
A. Create a SwiftUI project and add UIKit views manually later.
B. Create a Storyboard project and convert it to SwiftUI automatically.
C. Create two separate projects, one for SwiftUI and one for UIKit.
D. Use a third-party tool to combine SwiftUI and UIKit automatically.

Solution

  1. Step 1: Understand mixed UI support

    SwiftUI projects can embed UIKit views manually, allowing both UI styles.
  2. Step 2: Choose best project start

    Starting with SwiftUI is easier; you can add UIKit views as needed.
  3. Step 3: Evaluate other options

    Storyboard projects don't convert automatically; separate projects or tools are unnecessary.
  4. Final Answer:

    Create a SwiftUI project and add UIKit views manually later. -> Option A
  5. Quick Check:

    Start SwiftUI, add UIKit manually [OK]
Hint: Start SwiftUI project; add UIKit views manually if needed [OK]
Common Mistakes:
  • Expecting automatic conversion from Storyboard to SwiftUI
  • Creating two separate projects unnecessarily
  • Relying on third-party tools for basic UI mixing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard