Bird
0
0

You want to create a SwiftUI view that shows a list of names from an array and updates when the array changes. Which approach is best?

hard📝 Application Q8 of 15
iOS Swift - iOS Basics and Setup
You want to create a SwiftUI view that shows a list of names from an array and updates when the array changes. Which approach is best?
AUse a regular variable for the array and ForEach inside VStack.
BUse @State for the array and List view to display names.
CUse @StateObject for the array and Text views for each name.
DUse @Binding for the array and Button views for each name.
Step-by-Step Solution
Solution:
  1. Step 1: Choose state management for dynamic data

    @State is suitable for simple mutable data like an array in a view.
  2. Step 2: Use List to display dynamic collections

    List automatically updates when the @State array changes, showing each name.
  3. Final Answer:

    Use @State for the array and List view to display names. -> Option B
  4. Quick Check:

    @State + List = dynamic list UI [OK]
Quick Trick: Use @State with List for dynamic arrays [OK]
Common Mistakes:
  • Using regular variable prevents UI updates
  • Confusing @StateObject with @State for simple arrays
  • Using Button instead of List for display

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes