Bird
0
0

Which of the following is the correct syntax to add a searchable modifier with a binding to a @State variable named searchText?

easy📝 Syntax Q12 of 15
iOS Swift - Lists and Data Display
Which of the following is the correct syntax to add a searchable modifier with a binding to a @State variable named searchText?
A.searchable(searchText)
B.searchable($searchText)
C.searchable(text: $searchText)
D.searchable(text: searchText)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the searchable syntax

    The searchable modifier requires a binding to a string, written as text: $variable.
  2. Step 2: Match the correct binding syntax

    Using $searchText passes the binding, so the correct syntax is .searchable(text: $searchText).
  3. Final Answer:

    .searchable(text: $searchText) -> Option C
  4. Quick Check:

    Binding uses $ with variable name [OK]
Quick Trick: Use $ to bind @State variable in searchable [OK]
Common Mistakes:
  • Omitting the text: label
  • Not using $ for binding
  • Passing variable without binding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes