Challenge - 5 Problems
iOS Project Creator
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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() } }
Attempts:
2 left
💡 Hint
Think about the default text SwiftUI uses to greet you.
✗ Incorrect
The default ContentView in a new SwiftUI project shows a Text view with "Hello, world!" and some padding around it.
❓ lifecycle
intermediate2: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()
}
}
}Attempts:
2 left
💡 Hint
This struct tells the system where the app starts running.
✗ Incorrect
The @main attribute marks the app’s entry point. The struct conforming to App defines the main scene and UI window.
📝 Syntax
advanced2: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
}Attempts:
2 left
💡 Hint
The View protocol requires a body property.
✗ Incorrect
The View protocol requires a computed property named body returning some View. Missing it causes a conformance error.
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")
}
}
}Attempts:
2 left
💡 Hint
Navigation titles require a NavigationView container.
✗ Incorrect
You must wrap your content in NavigationView and then apply .navigationTitle modifier to set the title.
🧠 Conceptual
expert3: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()
}
}
}Attempts:
2 left
💡 Hint
Think about how iPad apps can have multiple windows.
✗ Incorrect
WindowGroup manages the app’s windows and scenes, enabling multiple windows on iPad and future multitasking features.