UIKit is Apple's foundational framework for building user interfaces in iOS, iPadOS, tvOS, and watchOS applications. It provides the window and view architecture needed to display content on screen, the infrastructure to handle user interactions through touch and gestures, and the tools to manage your app's data and content flow. Understanding UIKit is essential even in the SwiftUI era, as many production apps combine both frameworks, and UIKit's view controller lifecycle, Auto Layout system, and collection views remain the standard for complex interfaces.
What This Cheat Sheet Covers
This topic spans 30 focused tables and 247 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: View Hierarchy and Core View Classes
| Class | Example | Description |
|---|---|---|
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))view.backgroundColor = .red | • The fundamental building block for all visual elements • manages rectangular area on screen, handles drawing and touch events | |
parentView.addSubview(childView) | • Adds a view as a subview to another view's hierarchy • the child appears on top of the parent | |
childView.removeFromSuperview() | • Removes a view from its parent's subview hierarchy • automatically releases strong references | |
let children = parentView.subviews | • Array of all direct child views in the order they were added • read-only property | |
if let parent = view.superview { } | • Reference to the immediate parent view • nil if the view has no parent | |
parentView.bringSubviewToFront(childView) | Moves a subview to the top of the view hierarchy so it draws on top of siblings | |
parentView.sendSubviewToBack(backgroundView) | Moves a subview behind all other sibling views in the draw order | |
parentView.insertSubview(newView, at: 1) | Inserts a subview at a specific position in the subviews array, controlling z-order |