0
0
iOS Swiftmobile~10 mins

Search with searchable modifier 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 search bar to the list.

iOS Swift
List(items, id: \.self) { item in
    Text(item)
}
.[1](text: $searchText)
Drag options to blanks, or click blank then click option'
AsearchBar
Bsearch
Csearchable
DsearchField
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'search' instead of 'searchable' causes a compiler error.
Trying to use 'searchBar' which is not a SwiftUI modifier.
2fill in blank
medium

Complete the code to declare the search text state variable.

iOS Swift
@State private var [1] = ""
Drag options to blanks, or click blank then click option'
AsearchText
BsearchTerm
Cquery
DfilterText
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name without updating the binding causes the search bar not to work.
3fill in blank
hard

Fix the error in filtering the list based on search text.

iOS Swift
let filteredItems = items.filter { item in
    item.lowercased().contains([1].lowercased())
}
Drag options to blanks, or click blank then click option'
Aquery
BsearchText
CsearchTerm
DfilterText
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not declared causes a compile error.
Using the wrong variable name breaks the filtering logic.
4fill in blank
hard

Fill both blanks to create a filtered list that updates with search text.

iOS Swift
List([1]) { item in
    Text(item)
}
.searchable(text: $[2])
Drag options to blanks, or click blank then click option'
AfilteredItems
Bitems
CsearchText
DsearchTerm
Attempts:
3 left
💡 Hint
Common Mistakes
Showing all items instead of filtered items.
Binding searchable to a wrong variable.
5fill in blank
hard

Fill all three blanks to complete the search filtering logic.

iOS Swift
let filteredItems = [1].filter { item in
    item.[2]().contains(searchText.[3]())
}
Drag options to blanks, or click blank then click option'
Aitems
Blowercased
Cuppercased
Dcapitalized
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong array name causes errors.
Not using consistent casing causes search mismatches.