0
0
iOS Swiftmobile~10 mins

TextField 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 create a basic TextField with a placeholder.

iOS Swift
TextField("[1]", text: $name)
Drag options to blanks, or click blank then click option'
Aname
BEnter your name
CTextField
Dplaceholder
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.
2fill in blank
medium

Complete 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'
Ainput
Bname
Ctext
Demail
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.
3fill in blank
hard

Fix 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'
ApasswordText
Bpwd
Cpassword
Dpass
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.
4fill in blank
hard

Fill 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'
A.emailAddress
B.numberPad
CRoundedBorderTextFieldStyle
DPlainTextFieldStyle
Attempts:
3 left
💡 Hint
Common Mistakes
Using numberPad keyboard for email input.
Using PlainTextFieldStyle instead of RoundedBorderTextFieldStyle.
Missing parentheses after style name.
5fill in blank
hard

Fill 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'
AEnter username
Busername
Ctrue
Dfalse
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.