Skip to the workspace
Pebellslearn by building
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.

ios / Cocoa Touch

Explore each scene at your own pace.

01 · The rule

The rule

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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.