Activity 1
Present an editor sheet
Present a navigation-wrapped editor with medium and large detents, Save and Cancel actions, and a clear dismissal contract.
Hint: The editor should report completion rather than reach into the presenting screen.
UIKit Development
Present temporary tasks, request focused decisions, and compose controllers with correct containment lifecycles.
Before you begin
Learning stage
Presentation style communicates product meaning. Push for hierarchy; present a sheet for a temporary task that preserves context; use full screen only when immersion or workflow demands it. On iPad, popovers require a source view or bar button item. The presenter must be in the visible hierarchy and should not present a second controller during an active transition.
UIAlertController is appropriate for brief information or a small decision. Routine field validation belongs inline. Destructive choices should use a destructive action style and clear consequences. A sheet presentation controller can provide detents, a grabber, and expansion behavior without custom gesture code.
Child containment composes controllers within one screen. Call addChild, place and constrain the child's view, then call didMove(toParent:). Removal reverses the lifecycle with willMove(toParent: nil), view removal, and removeFromParent. Containment is not merely adding another controller's view; the relationship forwards appearance, traits, rotation, and environment behavior.
Learning stage
A reusable container embeds a child with the complete containment sequence.
func install(_ child: UIViewController, in container: UIView) {
addChild(child)
child.view.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(child.view)
NSLayoutConstraint.activate([
child.view.leadingAnchor.constraint(equalTo: container.leadingAnchor),
child.view.trailingAnchor.constraint(equalTo: container.trailingAnchor),
child.view.topAnchor.constraint(equalTo: container.topAnchor),
child.view.bottomAnchor.constraint(equalTo: container.bottomAnchor)
])
child.didMove(toParent: self)
}
func remove(_ child: UIViewController) {
child.willMove(toParent: nil)
child.view.removeFromSuperview()
child.removeFromParent()
}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
Present a navigation-wrapped editor with medium and large detents, Save and Cancel actions, and a clear dismissal contract.
Hint: The editor should report completion rather than reach into the presenting screen.
Activity 2
Create a container that transitions between loading, content, and error child controllers using correct containment calls.
Hint: Keep at most one active child and define the transition order.
Learning stage
Answer each question before revealing the explanation.
QUESTION 1
addChild, add/constrain the view, then didMove
Both the controller hierarchy and the view hierarchy must be established.
QUESTION 2
For important brief information or a small decision that deserves interruption.
Routine guidance and field validation are clearer inline.
Learning stage
Explain the design in terms of lifecycle, identity, ownership, system behavior, and trade-offs.
Short answer: Use hierarchy for deeper content, modal presentation for temporary tasks, and containment to compose controllers inside one screen.
The information relationship drives the choice. I also account for size-class behavior, dismissal, iPad popovers, and state restoration. Custom containment includes the documented parent-child lifecycle rather than only moving views.
Possible follow-ups
Learning stage
Presentation and containment APIs express relationships between tasks and screens. Correct semantics and lifecycle calls preserve system behavior.