0
0
iOS Swiftmobile~10 mins

Project structure in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the main app struct in SwiftUI.

iOS Swift
import SwiftUI

@main
struct MyApp: [1] {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}
Drag options to blanks, or click blank then click option'
AScene
BWindowGroup
CView
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using View instead of App
Using Scene instead of App
2fill in blank
medium

Complete the code to create a SwiftUI view named ContentView.

iOS Swift
import SwiftUI

struct ContentView: [1] {
  var body: some View {
    Text("Hello, world!")
  }
}
Drag options to blanks, or click blank then click option'
AView
BWindowGroup
CScene
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using App instead of View
Using Scene instead of View
3fill in blank
hard

Fix the error in the code by completing the missing property wrapper for state management.

iOS Swift
struct CounterView: View {
  [1] var count = 0

  var body: some View {
    VStack {
      Text("Count: \(count)")
      Button("Increment") {
        count += 1
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A@Binding
B@ObservedObject
C@State
D@EnvironmentObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using @ObservedObject without an observable class
Using @Binding without a source
4fill in blank
hard

Fill both blanks to create a filter-map chain that filters words longer than 3 characters.

iOS Swift
let words = ["apple", "cat", "dog", "banana"]
let filtered = words.filter { $0.[1] > 3 }.map { $0.[2] }
Drag options to blanks, or click blank then click option'
Acount
Buppercased()
Clowercased()
DisEmpty
Attempts:
3 left
💡 Hint
Common Mistakes
Using isEmpty for length
Using lowercased() when uppercase is needed
5fill in blank
hard

Fill all three blanks to create a SwiftUI view with a button that toggles a boolean state.

iOS Swift
struct ToggleView: View {
  [1] var isOn = false

  var body: some View {
    Button(action: {
      isOn = !isOn
    }) {
      Text(isOn ? [2] : [3])
    }
  }
}
Drag options to blanks, or click blank then click option'
A@State
B"On"
C"Off"
D@Binding
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Binding without a source
Swapping "On" and "Off" texts