Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
iOS Architecture  ›  Capstone Project

Cocoa Touch

Cocoa Touch 12 minCocoa Touch is the top iOS layer, including UIKit, SwiftUI and notifications, and it handles what users see and touch on the main thread.

Cocoa Touch

Everything the hiker actually touches in TrailLog — the list of hikes, the "Log hike" button, the swipe to delete, the reminder notification — comes from the top layer of iOS. Cocoa Touch is where your app meets the person holding the phone.

The rule

Cocoa Touch turns the layers below into screens, touches and app life.

The top layer holds the frameworks that make an app feel like an iPhone app:

  • UIKit — views, view controllers, controls, navigation, text input, and the event loop that delivers touches. It also manages the app lifecycle: launching, going to the background, coming back.
  • SwiftUI — Apple's newer declarative UI framework, built alongside UIKit (and in places on top of it).
  • User Notifications — local and push notifications.
  • Gesture recognisers — taps, swipes, pinches and long presses turned into simple callbacks.
  • Other frameworks for user-facing features: MapKit (maps), PhotosUI (photo picker), WidgetKit (home-screen widgets).

Cocoa Touch is a heavy user of the layers below. A UIButton draws with Core Graphics, animates its highlight with Core Animation, and stores its title as a Foundation String.

import UIKit

let logButton = UIButton(type: .system)
logButton.setTitle("Log hike", for: .normal)
logButton.addTarget(self, action: #selector(logHike), for: .touchUpInside)

That one import UIKit also brings in Foundation, which is why most UIKit files need no separate import Foundation.

A key rule of this layer: UI work happens on the main thread. UIKit is not thread-safe, so every change to a view must be made from the main thread, which also runs the event loop.

The shortcut

Ask: "Does the user see it or touch it?" If yes, start in Cocoa Touch. If not, look lower.

Sorting TrailLog features by layerStep 1 of 4
  1. A "Log hike" button

    The user touches it → Cocoa Touch (UIKit's UIButton or a SwiftUI Button).

The trap is putting non-visual work, like parsing a big file, into a view controller on the main thread. The layer rule and the main-thread rule together say: keep Cocoa Touch for what the user sees, and do slow work elsewhere.

Drills

Answer fast — trust the rule.

quick drill

Which layer contains UIKit?

quick drill

A daily hiking reminder appears on the lock screen. Which framework schedules it?

quick drill

On which thread must you update a UILabel's text?

quick drill

Which statement about Cocoa Touch and the lower layers is true?

Remember

  • Cocoa Touch is the top layer: UIKit, SwiftUI, notifications, gestures and the app lifecycle.
  • Shortcut: if the user sees or touches it, start in Cocoa Touch.
  • Trap: UI changes only on the main thread — keep slow, invisible work out of it.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFollow one tap down the stack

The hiker taps "Log hike" in TrailLog. The app records the location, saves the hike, and shows a checkmark that fades in. Walk through which layer handles each step, and say which steps must run on the main thread.