Activity 1
Build a profile form
Create name, email, and biography fields with correct content types, return-key progression, inline errors, and keyboard-safe scrolling.
Hint: Test hardware keyboard navigation and large text.
UIKit Development
Create accessible forms with appropriate input semantics, keyboard-safe layout, focus flow, and helpful validation.
Before you begin
Learning stage
A form is a small state machine, not merely a vertical set of fields. Each input has raw text, normalized value, validation state, focus state, and submission behavior. UITextField suits single-line input; UITextView handles longer editable text. Configure keyboard type, text content type, capitalization, return key, and secure entry to match meaning.
The keyboard changes available space. Prefer keyboardLayoutGuide for constraints that should follow the keyboard and scroll views for content that may exceed the remaining viewport. Avoid one global magic offset; floating, split, hardware, and international keyboards do not share a single height.
Validate progressively without punishing normal editing. Required checks can happen on blur or submit, while server-dependent validation belongs to submission. Keep error text next to the field, preserve what the user entered, focus the first invalid field when helpful, and never communicate an error only through color.
Learning stage
This form keeps its action above the keyboard and validates a normalized email when submitted.
private let emailField = UITextField()
private let errorLabel = UILabel()
private let continueButton = UIButton(configuration: .filled())
private func configureForm() {
emailField.keyboardType = .emailAddress
emailField.textContentType = .emailAddress
emailField.autocapitalizationType = .none
emailField.returnKeyType = .done
errorLabel.textColor = .systemRed
errorLabel.numberOfLines = 0
errorLabel.isHidden = true
continueButton.addAction(UIAction { [weak self] _ in self?.submit() },
for: .primaryActionTriggered)
continueButton.bottomAnchor.constraint(
lessThanOrEqualTo: view.keyboardLayoutGuide.topAnchor,
constant: -12
).isActive = true
}
private func submit() {
let email = emailField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
guard email.contains("@") else {
errorLabel.text = "Enter an email address such as name@example.com."
errorLabel.isHidden = false
emailField.becomeFirstResponder()
return
}
errorLabel.isHidden = true
view.endEditing(true)
}Learning stage
Connect the UIKit concept to complete, maintainable application features.
Learning stage
Identify lifecycle, ownership, identity, layout, accessibility, and user-experience risks.
Learning stage
Build the behavior in a small Xcode project and inspect it across realistic states.
Activity 1
Create name, email, and biography fields with correct content types, return-key progression, inline errors, and keyboard-safe scrolling.
Hint: Test hardware keyboard navigation and large text.
Activity 2
Define validation for untouched, editing, valid, and invalid fields and decide when each message should appear.
Hint: Separate pure validation from UI presentation.
Learning stage
Answer each question before revealing the explanation.
QUESTION 1
It follows the keyboard's actual position and configuration
Keyboard sizes and positions vary, especially with floating, split, and hardware keyboards.
QUESTION 2
No. Provide explicit nearby text and accessible semantics.
Color alone may be imperceptible or ambiguous and does not explain how to recover.
Learning stage
Explain the design in terms of lifecycle, identity, ownership, system behavior, and trade-offs.
Short answer: Model field state, configure semantic input, manage focus and keyboard layout, and present validation at useful times.
I separate raw input, normalization, local validation, and submission. Content types improve autofill, a scroll view and keyboard layout guide protect visibility, and errors are textual, accessible, and preserve user input. Server errors are mapped back to fields or a clear form-level message.
Possible follow-ups
Learning stage
Reliable forms combine semantic fields, adaptive keyboard handling, explicit focus, and validation that helps users recover without losing work.