0
0
iOS Swiftmobile~20 mins

Empty state handling in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Empty State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will the UI show when the data array is empty?
Consider this SwiftUI view that shows a list or an empty state message. What will the user see if the data array is empty?
iOS Swift
struct ContentView: View {
  let data: [String]
  var body: some View {
    if data.isEmpty {
      Text("No items found.")
        .foregroundColor(.gray)
        .italic()
    } else {
      List(data, id: \.self) { item in
        Text(item)
      }
    }
  }
}
AA runtime error because the list has no data
BAn empty list with no rows visible
CA gray italic text saying "No items found."
DA blank white screen with no text
Attempts:
2 left
💡 Hint
Look at the condition that checks if data.isEmpty and what it shows.
lifecycle
intermediate
2:00remaining
When should you update the empty state UI in a SwiftUI view?
You have a SwiftUI view showing a list or an empty state message. When is the best time to update the UI to reflect changes in the data source?
AWhenever the data source changes, the view should update automatically if data is a @State or @ObservedObject property
BOnly when the view appears for the first time
CManually call a function to refresh the UI every second
DUpdate the UI only when the app restarts
Attempts:
2 left
💡 Hint
Think about how SwiftUI reacts to changes in @State or @ObservedObject properties.
🔧 Debug
advanced
2:00remaining
Why does the empty state text not appear in this UIKit code?
This UIKit code tries to show a label when the data array is empty, but the label never appears. What is the cause?
iOS Swift
class ViewController: UIViewController {
  let data: [String] = []
  let emptyLabel = UILabel()

  override func viewDidLoad() {
    super.viewDidLoad()
    emptyLabel.text = "No data available"
    emptyLabel.textColor = .gray
    emptyLabel.textAlignment = .center
    if data.isEmpty {
      view.addSubview(emptyLabel)
    }
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    emptyLabel.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: 50)
    emptyLabel.center = view.center
  }
}
AThe label is never added to the view hierarchy
BThe label is behind other views and not visible
CThe label text is empty so nothing shows
DThe label is added but has zero size because frame is set after viewDidLayoutSubviews
Attempts:
2 left
💡 Hint
Think about view layering and if other views cover the label.
navigation
advanced
2:00remaining
How to navigate from an empty state view to a data entry screen in SwiftUI?
You want to show a button on the empty state screen that navigates to a data entry view. Which code snippet correctly implements this navigation?
AAdd a gesture recognizer to the empty state text to push DataEntryView
BButton(action: { NavigationLink(destination: DataEntryView()) }) { Text("Add Item") }
CUse a modal presentation without NavigationLink or NavigationView
DNavigationLink(destination: DataEntryView()) { Text("Add Item") } inside the empty state view
Attempts:
2 left
💡 Hint
NavigationLink is the standard way to navigate in SwiftUI inside a NavigationView.
🧠 Conceptual
expert
2:00remaining
Why is handling empty states important in mobile app UX?
Choose the best explanation for why empty state handling improves user experience in mobile apps.
AIt guides users on what to do next and prevents confusion when no data is available
BIt reduces app size by not loading data unnecessarily
CIt improves app performance by skipping UI rendering
DIt allows the app to crash gracefully when data is missing
Attempts:
2 left
💡 Hint
Think about how users feel when they see an empty screen with no explanation.