0
0
iOS Swiftmobile~10 mins

Pull-to-refresh (refreshable) 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 add a pull-to-refresh modifier to the List.

iOS Swift
List(items, id: \.self) { item in
    Text(item)
}
.[1] {
    print("Refreshing data...")
}
Drag options to blanks, or click blank then click option'
AonTapGesture
BonAppear
ConDisappear
Drefreshable
Attempts:
3 left
💡 Hint
Common Mistakes
Using onAppear instead of refreshable.
Trying to add pull-to-refresh without the refreshable modifier.
2fill in blank
medium

Complete the async closure to simulate data refresh with a 2-second delay.

iOS Swift
.refreshable {
    await Task.sleep(UInt64([1] * 1_000_000_000))
    print("Data refreshed")
}
Drag options to blanks, or click blank then click option'
A3
B2
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 without converting to nanoseconds.
Using 2000000000 without multiplying by UInt64.
3fill in blank
hard

Fix the error by completing the code to update the items array after refresh.

iOS Swift
.refreshable {
    await Task.sleep(2_000_000_000)
    [1] = ["Apple", "Banana", "Cherry"]
}
Drag options to blanks, or click blank then click option'
Aself.items
Bitems
Cvar items
Dlet items
Attempts:
3 left
💡 Hint
Common Mistakes
Using var or let inside the closure which causes redeclaration errors.
Not using self when required inside closures.
4fill in blank
hard

Fill both blanks to declare the items array and bind it to the List.

iOS Swift
@State private var [1] = ["Orange", "Grape"]

var body: some View {
    List([2], id: \.self) { fruit in
        Text(fruit)
    }
}
Drag options to blanks, or click blank then click option'
Aitems
Bfruits
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the state variable and List data source.
Forgetting to mark the variable with @State.
5fill in blank
hard

Fill all three blanks to create a refreshable List that updates items after a delay.

iOS Swift
@State private var [1] = ["Cat", "Dog"]

var body: some View {
    List([2], id: \.self) { pet in
        Text(pet)
    }
    .refreshable {
        await Task.sleep([3])
        self.[1] = ["Cat", "Dog", "Rabbit"]
    }
}
Drag options to blanks, or click blank then click option'
Apets
Bitems
C2_000_000_000
D1_000_000_000
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the state and List data source.
Using 1_000_000_000 for 2 seconds delay.