0
0
iOS Swiftmobile~20 mins

First iOS app in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
First iOS App Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will this SwiftUI code display?
Consider this SwiftUI view code. What text will appear on the screen when the app runs?
iOS Swift
import SwiftUI

struct ContentView: View {
  var body: some View {
    Text("Welcome to my first app!")
      .font(.title)
      .foregroundColor(.blue)
  }
}
AA large red text saying 'Welcome to my first app!'
BA small blue text saying 'Welcome to my first app!'
CA large blue text saying 'Welcome to my first app!'
DNo text appears because of a syntax error
Attempts:
2 left
💡 Hint
Look at the modifiers .font(.title) and .foregroundColor(.blue).
navigation
intermediate
2:00remaining
What happens when this button is tapped?
This SwiftUI code shows a button inside a NavigationView. What happens when the user taps the button?
iOS Swift
import SwiftUI

struct ContentView: View {
  var body: some View {
    NavigationView {
      NavigationLink("Go to Details", destination: Text("Details Screen"))
        .navigationTitle("Home")
    }
  }
}
AThe button shows an alert instead of navigating.
BThe button does nothing because NavigationLink is missing an action.
CThe app crashes due to missing navigation controller.
DThe app navigates to a new screen showing 'Details Screen' text.
Attempts:
2 left
💡 Hint
NavigationLink creates a tappable link to a destination view.
lifecycle
advanced
2:00remaining
When is the body property of a SwiftUI View recomputed?
Given this SwiftUI view with a @State variable, when does the body property get recomputed?
iOS Swift
import SwiftUI

struct ContentView: View {
  @State private var count = 0

  var body: some View {
    VStack {
      Text("Count: \(count)")
      Button("Increment") {
        count += 1
      }
    }
  }
}
AOnly when the app restarts.
BEach time the count variable changes, the body recomputes to update the UI.
CEvery second automatically, regardless of state changes.
DOnly once when the view is created; state changes do not affect body.
Attempts:
2 left
💡 Hint
Think about how @State triggers UI updates.
📝 Syntax
advanced
2:00remaining
What error does this SwiftUI code produce?
Examine this SwiftUI code snippet. What error will it cause when compiling?
iOS Swift
import SwiftUI

struct ContentView: View {
  var body: some View {
    VStack {
      Text("Hello")
      Button("Tap me") {
        count += 1
      }
    }
  }
}
ARuntime error: count variable not initialized.
BNo error; code runs fine.
CSyntax error: Missing closure for Button action.
DType error: Text cannot be inside VStack.
Attempts:
2 left
💡 Hint
Check the Button syntax and its action closure.
🔧 Debug
expert
3:00remaining
Why does this SwiftUI view not update the text when the button is tapped?
This code intends to update the displayed text when the button is tapped, but it does not. Why?
iOS Swift
import SwiftUI

struct ContentView: View {
  var count = 0

  var body: some View {
    VStack {
      Text("Count: \(count)")
      Button("Increment") {
        count += 1
      }
    }
  }
}
ABecause count is a regular variable, not a @State property, so changes don't trigger UI updates.
BBecause the Button label is incorrect and does not trigger the action.
CBecause the Text view is outside the VStack.
DBecause the count variable is declared as a constant.
Attempts:
2 left
💡 Hint
Think about how SwiftUI tracks changes to update the UI.