LEARNING DEMO · The browser preview uses simulated values. It does not compile Swift, read sensors, alter login items, or purge memory. Downloaded source is a starting example, not a tested telemetry utility.
Swift 6 & SwiftUI macOS 15 Sequoia Xcode 16 Ready 35 min read Difficulty: Intermediate

Building a Native macOS Menu Bar Utility with SwiftUI

Explore a MenuBarExtra scene, an observable data model, and an optional login-item manager. The on-page interface is a browser simulation; use Xcode to build native Swift code.

AR
Tech2Apple editorial verified Source-based learning guide
Review current Apple documentation for your deployment target
commit Starter source • memory Illustrative SwiftUI example
terminal

Interactive Sandbox & Menu Bar Engine

import SwiftUI
import AppKit

@main
struct MenuBarMonitorApp: App {
    @StateObject private var telemetry = SystemTelemetry()

    var body: some Scene {
        MenuBarExtra("Silicon Pulse", systemImage: "cpu.fill") {
            VStack(alignment: .leading, spacing: 12) {
                Text("Silicon Pulse").font(.headline)
                Text(telemetry.summary).font(.caption)
                Button("Update sample") { telemetry.updateSample() }
                Divider()
                Button("Quit") { NSApplication.shared.terminate(nil) }
            }
            .padding(16)
            .frame(width: 260)
        }
        .menuBarExtraStyle(.window)
    }
}
Browser simulation ready · no Swift compilation
Zero warnings
Finder
memory 42% • 38°C
wifi battery_charging_full Thu 10:42
memory

SiliconPulse

Apple M4 Max • 16-Core

Active Loop
speed CPU Cores (12P + 4E) 42.8%
P-Cores: 52% Load E-Cores: 18% Load
analytics Unified Memory 18.4 / 36.0 GB
Pressure: Nominal Swap: 0 MB Active
thermostat SoC Temp: 38.2°C
Fan: 0 RPM (Silent)
Launch at Login SMAppService.mainApp
Reactive Task.sleep(nanoseconds: 2_000_000_000) polling
CURRICULUM • 4 Core Implementation Modules

Complete Step-by-Step Implementation

Follow the source example to understand a menu bar scene, observable state, and an optional login-item manager. Production telemetry, signing, and distribution require additional implementation and testing.

checklist

System Prerequisites

Ensure your development workstation meets these toolchain baselines before compiling.

STEP 01

The App Lifecycle Without NSApplicationDelegate

Traditional macOS menu bar apps required an Objective-C or AppKit boilerplate relying on NSStatusItem and subclassing NSApplicationDelegate.

With modern SwiftUI in macOS 13+, the entire application can be expressed as a pure declarative MenuBarExtra scene. To completely hide the icon from the macOS Dock, add a single key to your Info.plist:

<key>LSUIElement</key>
<true/>
SiliconPulseApp.swift Declarative Scene
import SwiftUI
import AppKit

@main
struct MenuBarMonitorApp: App {
    @StateObject private var telemetry = SystemTelemetry()

    var body: some Scene {
        MenuBarExtra("Silicon Pulse", systemImage: "cpu.fill") {
            VStack(alignment: .leading, spacing: 12) {
                Text("Silicon Pulse").font(.headline)
                Text(telemetry.summary).font(.caption)
                Button("Update sample") { telemetry.updateSample() }
                Divider()
                Button("Quit") { NSApplication.shared.terminate(nil) }
            }
            .padding(16)
            .frame(width: 260)
        }
        .menuBarExtraStyle(.window)
    }
}
STEP 02

Model Sample Data with ObservableObject

Start with a main-actor model and published sample state. This keeps UI updates easy to understand before you introduce real system measurements. The downloaded example does not call kernel APIs.

bolt

Concurrency Note: In Swift 6, encapsulate Darwin calls within an isolated actor to satisfy data-race safety across asynchronous timer iterations.

MachReader.swift Swift 6 Actor
import Foundation
import Combine

// Sample values for learning UI state. This does not read hardware sensors.
@MainActor
final class SystemTelemetry: ObservableObject {
    @Published var summary = "Demo values — not live telemetry"
    private var updates = 0

    func updateSample() {
        updates += 1
        summary = "Sample update \(updates) — simulated data"
    }
}
STEP 03

Launch at Login via SMAppService

Forget deprecated SMLoginItemSetEnabled or nested Helper App targets. Apple’s modern ServiceManagement framework lets your main application binary register itself directly with launchd.

The user maintains full transparency in System Settings > General > Login Items, and status inspection is instantaneous.

LaunchAgentService.swift macOS 13+ API
import ServiceManagement

// Optional: call from a signed app after explaining the user's choice.
// This helper is not invoked by the sample UI.
@MainActor
final class LaunchAgentManager {
    func setEnabled(_ enabled: Bool) throws {
        if enabled {
            try SMAppService.mainApp.register()
        } else {
            try SMAppService.mainApp.unregister()
        }
    }
}
STEP 04

Sandboxing, Notarization & Distribution

To distribute outside the Mac App Store while avoiding Gatekeeper warnings, sign your binary with Developer ID Application credentials and staple notarization tickets. For reading non-standard hardware sensors (e.g. discrete GPU temperatures), understand when to request com.apple.security.temporary-exception.iokit-user-client-class.

verified_user
NotaryTool Hardened Runtime Ready
Curated Apple Developer video Watch on YouTube
RELATED LEARNING VIDEO

Watch Apple’s Swift Playgrounds introduction

A related introduction from Apple Developer. This video teaches SwiftUI app creation; it is not an original Tech2Apple recording of this menu bar project.

WHAT TO BUILD NEXT

Next Tutorials in macOS Track

View Track Syllabus arrow_forward
rocket_launch SILICON ARCHITECTURE DISPATCH

Keep exploring Apple development

Follow the published guide collection through RSS. Original videos and measured benchmark reports will be added when available.

Email subscriptions are not enabled. Follow the RSS feed for published guides.