0
0
iOS Swiftmobile~10 mins

Why lists present dynamic content in iOS Swift - Test Your Understanding

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

Complete the code to create a SwiftUI List that shows items from an array.

iOS Swift
List([1]) { item in
    Text(item)
}
Drag options to blanks, or click blank then click option'
AVStack
BText
Citems
DButton
Attempts:
3 left
💡 Hint
Common Mistakes
Using UI elements like Text or Button instead of the data array.
Leaving the List empty without data.
2fill in blank
medium

Complete the code to make the List update when the data changes.

iOS Swift
@State private var fruits = ["Apple", "Banana", "Cherry"]

var body: some View {
    List([1]) { fruit in
        Text(fruit)
    }
}
Drag options to blanks, or click blank then click option'
Afruits
Bself.fruits
C@fruits
Dvar fruits
Attempts:
3 left
💡 Hint
Common Mistakes
Adding self. inside the List parameter causes errors.
Using @fruits is invalid syntax here.
3fill in blank
hard

Fix the error in the List code by completing the blank with the correct identifier for unique items.

iOS Swift
List(fruits, id: [1]) { fruit in
    Text(fruit)
}
Drag options to blanks, or click blank then click option'
Aself
Bid
Cfruit
D\.self
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or self without the backslash causes errors.
Using fruit is invalid here.
4fill in blank
hard

Fill both blanks to create a List that shows numbers from 1 to 5 with their squares.

iOS Swift
let numbers = Array(1...5)

List(numbers, id: [1]) { num in
    Text("\(num) squared is \(num [2] num)")
}
Drag options to blanks, or click blank then click option'
A\.self
B*
C+
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * changes the meaning.
Using num as id without backslash causes errors.
5fill in blank
hard

Fill all three blanks to create a dynamic List showing names and ages from a dictionary.

iOS Swift
let people = ["Alice": 30, "Bob": 25, "Carol": 27]

List(people.keys.sorted(), id: [1]) { name in
    Text(name)
    Text("Age: \(people[[2]] ?? 0)")
    Text("Name length: \([3].count)")
}
Drag options to blanks, or click blank then click option'
A\.self
Bname
Dpeople
Attempts:
3 left
💡 Hint
Common Mistakes
Using people as id causes errors.
Using wrong variable names inside the Text views.