0
0
iOS Swiftmobile~20 mins

Creating a new iOS project in iOS Swift - Practice Exercises

Choose your learning style9 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.