0
0
iOS Swiftmobile~5 mins

TextField in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a TextField in iOS Swift?
A TextField is a UI element that lets users enter and edit text in an app. It looks like a box where you can type.
Click to reveal answer
beginner
How do you create a simple TextField in SwiftUI?
Use TextField("Placeholder", text: $variable) where variable stores the typed text.
Click to reveal answer
intermediate
What is the purpose of the @State property wrapper with a TextField?
@State keeps track of the text typed by the user and updates the UI when the text changes.
Click to reveal answer
intermediate
How can you customize the keyboard type for a TextField?
Use the .keyboardType() modifier with options like .numberPad or .emailAddress to show the right keyboard.
Click to reveal answer
beginner
Why is accessibility important for TextField?
Accessibility helps users with disabilities use the TextField by providing labels and hints for screen readers.
Click to reveal answer
Which SwiftUI code creates a TextField with a placeholder "Enter name"?
ATextField("Enter name", text: $name)
BTextField($name, "Enter name")
CTextField(text: $name)
DTextField("name")
What does the @State property do when used with a TextField?
ADisables the text field
BCreates a new keyboard
CChanges the font size
DStores and updates the text input by the user
How do you change the keyboard to show numbers only for a TextField?
A.keyboardType(.emailAddress)
B.keyboardType(.numberPad)
C.keyboardType(.default)
D.keyboardType(.asciiCapable)
Which modifier adds a label for screen readers to a TextField?
A.accessibilityLabel("label")
B.font(.label)
C.textContentType("label")
D.keyboardType("label")
What happens if you forget to bind a TextField to a @State variable?
AThe keyboard won’t appear
BThe app crashes immediately
CThe text field won’t update or store user input
DThe text field becomes read-only
Explain how to create a basic TextField in SwiftUI and why binding with @State is necessary.
Think about how the app remembers what the user types.
You got /3 concepts.
    Describe how to improve accessibility for a TextField in an iOS app.
    Consider users who rely on voice feedback.
    You got /3 concepts.