Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a basic TextField with a placeholder.
iOS Swift
TextField("[1]", text: $name)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name instead of placeholder text.
Leaving the placeholder empty.
Confusing the placeholder with the binding variable.
✗ Incorrect
The placeholder text inside the TextField is the first argument, shown when the field is empty.
2fill in blank
mediumComplete the code to bind the TextField text to a state variable called 'email'.
iOS Swift
@State private var email = "" TextField("Email", text: $[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name in the binding.
Forgetting the $ before the variable.
Binding to a non-state variable.
✗ Incorrect
The text binding uses $ followed by the state variable name to keep the TextField and variable in sync.
3fill in blank
hardFix the error in the code to make the TextField secure for password input.
iOS Swift
SecureField("Password", text: $[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist.
Forgetting to declare the @State variable.
Using TextField instead of SecureField for passwords.
✗ Incorrect
The binding variable must match the @State variable holding the password text, commonly named 'password'.
4fill in blank
hardFill both blanks to create a TextField with rounded border style and a keyboard type for email input.
iOS Swift
TextField("Email", text: $email) .keyboardType([1]) .textFieldStyle([2]())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numberPad keyboard for email input.
Using PlainTextFieldStyle instead of RoundedBorderTextFieldStyle.
Missing parentheses after style name.
✗ Incorrect
Use .emailAddress keyboard type for email input and RoundedBorderTextFieldStyle for a nice border.
5fill in blank
hardFill all three blanks to create a TextField with a placeholder, bind it to 'username', and disable autocorrection.
iOS Swift
TextField("[1]", text: $[2]) .autocorrectionDisabled([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using false to disable autocorrection (it enables it).
Binding to a variable not declared with @State.
Leaving the placeholder empty.
✗ Incorrect
The placeholder is 'Enter username', the binding variable is 'username', and autocorrectionDisabled(true) turns off autocorrect.