A List in SwiftUI is a view that displays rows of data in a single column, similar to a table. It is used to show collections of items in a scrollable list.
Click to reveal answer
beginner
How do you create a simple list of static text items in SwiftUI?
You use List with static views inside, like: List { Text("Item 1") Text("Item 2") }
Click to reveal answer
intermediate
What is the purpose of the ForEach inside a List?
ForEach lets you create a list from a dynamic collection of data by repeating views for each item.
Click to reveal answer
intermediate
Why do items in a List need to be Identifiable?
SwiftUI needs to know how to uniquely identify each item to manage updates and animations efficiently. Making items Identifiable provides a unique ID for each.
Click to reveal answer
beginner
How can you add a navigation title to a List in SwiftUI?
Wrap the List in a NavigationView and use .navigationTitle("Title") modifier on the List or its container.
Click to reveal answer
Which SwiftUI view is used to display a scrollable list of rows?
AVStack
BList
CHStack
DZStack
✗ Incorrect
List is the view designed for scrollable lists of rows.
What does ForEach do inside a List?
AAdds a button to the list
BCreates a single static row
CRepeats views for each item in a collection
DChanges the list background color
✗ Incorrect
ForEach repeats views for each item in a data collection.
Why must items in a List be Identifiable?
ATo allow SwiftUI to track each item uniquely
BTo change font size
CTo display images
DTo add animations manually
✗ Incorrect
Identifiable items let SwiftUI track and update each row efficiently.
How do you add a title to a List screen?
AUse .title() modifier on List
BUse .font() modifier on List
CAdd Text above List
DWrap List in NavigationView and use .navigationTitle()
✗ Incorrect
NavigationView with .navigationTitle() sets the screen title.
Which of these is NOT a correct way to create a List?
AList { VStack { Text("One") Text("Two") } }
BList(items) { item in Text(item) }
CList { Text("One") Text("Two") }
DList { ForEach(items) { item in Text(item) } }
✗ Incorrect
Wrapping rows inside VStack inside List creates only one row, not multiple.
Explain how to create a dynamic list of items in SwiftUI and why Identifiable is important.
Think about how SwiftUI knows which row is which when data changes.
You got /5 concepts.
Describe how to add a navigation title to a list screen in SwiftUI.
Remember the container that enables navigation features.
You got /4 concepts.
Practice
(1/5)
1. What does the List view in SwiftUI primarily do?
easy
A. Displays multiple items vertically and allows scrolling if needed
B. Creates a horizontal stack of buttons
C. Shows a single image on the screen
D. Plays a video in full screen
Solution
Step 1: Understand the purpose of List
The List view is designed to show many items arranged vertically.
Step 2: Recognize scrolling behavior
If the items exceed the screen height, List allows vertical scrolling automatically.
Final Answer:
Displays multiple items vertically and allows scrolling if needed -> Option A
Quick Check:
List shows vertical scrollable items = B [OK]
Hint: List shows vertical scrollable items [OK]
Common Mistakes:
Confusing List with horizontal stacks
Thinking List shows only one item
Assuming List plays media content
2. Which of the following is the correct syntax to create a simple list from an array of strings named fruits?
easy
A. List { fruits }
B. List(fruits) { fruit in Text(fruit) }
C. List(fruits, id: fruit) { Text(fruit) }
D. List(fruits, id: \.self) { fruit in Text(fruit) }
Solution
Step 1: Identify correct List initializer
For simple arrays, use List(data, id: \.self) to uniquely identify each item.
Step 2: Check closure syntax
The closure receives each item and returns a Text view displaying it.
Final Answer:
List(fruits, id: \.self) { fruit in Text(fruit) } -> Option D
Quick Check:
Use id: \.self for simple arrays = C [OK]
Hint: Use id: \.self for simple array lists [OK]
Common Mistakes:
Omitting id: \.self causes errors
Passing id: fruit instead of id: \.self
Using List without closure for data
3. Given this code snippet, what will be displayed?
struct ContentView: View {
let numbers = [1, 2, 3]
var body: some View {
List(numbers, id: \.self) { num in
Text("Number: \(num * 2)")
}
}
}
medium
A. Number: 1, Number: 4, Number: 9
B. Number: 1, Number: 2, Number: 3
C. Number: 2, Number: 4, Number: 6
D. Number: 0, Number: 1, Number: 2
Solution
Step 1: Understand the data and transformation
The array contains 1, 2, 3. Each number is multiplied by 2 in the Text view.
Step 2: Calculate displayed values
1*2=2, 2*2=4, 3*2=6, so the list shows "Number: 2", "Number: 4", "Number: 6".
Final Answer:
Number: 2, Number: 4, Number: 6 -> Option C
Quick Check:
Multiply each number by 2 = A [OK]
Hint: Check how data transforms inside Text closure [OK]
Common Mistakes:
Ignoring the multiplication inside the string
Confusing array values with displayed text
Assuming original numbers are shown
4. What is wrong with this SwiftUI List code?
struct ContentView: View {
let items = ["A", "B", "C"]
var body: some View {
List(items) { item in
Text(item)
}
}
}
medium
A. Missing id parameter for simple array causes a compile error
B. Text view cannot display strings directly
C. List requires items to be Int type
D. Closure syntax is incorrect
Solution
Step 1: Check List initializer requirements
When using List with simple arrays like [String], you must provide an id parameter to identify each element uniquely.
Step 2: Identify missing id parameter
The code omits id: \.self, so it will cause a compile-time error.
Final Answer:
Missing id parameter for simple array causes a compile error -> Option A
Quick Check:
Simple arrays need id: \.self in List = D [OK]
Hint: Always add id: \.self for simple arrays in List [OK]
Common Mistakes:
Assuming List infers id automatically
Thinking Text can't display strings
Believing List only works with Int arrays
5. You have a custom struct Person conforming to Identifiable with a unique id. How do you create a List to display each person's name?
hard
A. List(people, id: \.name) { person in Text(person.name) }
B. List(people) { person in Text(person.name) }
C. List(people, id: \.self) { person in Text(person.name) }
D. List(people) { Text(person.name) }
Solution
Step 1: Understand Identifiable protocol usage
If Person conforms to Identifiable, List can use the id property automatically without specifying id parameter.
Step 2: Use List with closure accessing person.name
Simply pass people array and provide closure to show Text with person.name.
Final Answer:
List(people) { person in Text(person.name) } -> Option B
Quick Check:
Identifiable lets List infer id automatically = A [OK]
Hint: Use List(people) if Person is Identifiable [OK]
Common Mistakes:
Adding redundant id parameter when Identifiable is used
Using wrong key path for id
Omitting closure parameter name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.