Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2026 Developer ToolsSystem Services

WWDC26 · 18 min · Developer Tools / System Services

Meet the new MetricKit

Find and fix performance problems faster than ever. Join us to explore how MetricKit equips you with vital performance metrics and actionable diagnostics to help you understand exactly where your app has opportunities for improvements. We’ll also cover how to intersect your app’s metrics and diagnostics by app state by using the StateReporting framework, providing you with the full picture to investigate optimizations in your app’s experience.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

Code shown on screen · 9 snippets

Receive metrics from MetricKit swift · at 4:59 ↗
// Receive metrics from MetricKit

import MetricKit

let manager = MetricManager()

for await report in manager.metricReports {
    processReport(report)
}
Send your metrics to the server swift · at 5:25 ↗
// Send your metrics to the server

import MetricKit

for await report in manager.metricReports {
    let jsonData = try JSONEncoder().encode(report)
    sendToServer(jsonData)
}
Access your performance metrics swift · at 5:44 ↗
// Access your performance metrics

import MetricKit

for await report in manager.metricReports {
    let intervalEntries = report.intervalEntries
    let fullDayEntry = intervalEntries.fullDayEntry
    
    for entry in intervalEntries {
        let memoryMetrics = entry.values.filter { $0.metricGroup == .memory }
        
        for metric in memoryMetrics {
            switch metric {
            case .peakMemory(let peak):
                processPeakMemory(peak)
            default: break
            }
        }
    }
}
Receive diagnostics swift · at 8:59 ↗
// Receive diagnostics

import MetricKit

let manager = MetricManager()

for await report in manager.diagnosticReports {
    processReport(report)
}
Send your diagnostic data to the server swift · at 9:14 ↗
// Send your diagnostic data to the server

import MetricKit

for await report in manager.diagnosticReports {
    let jsonData = try JSONEncoder().encode(report)
    sendToServer(jsonData)
}
Access your diagnostic data swift · at 9:39 ↗
// Access your diagnostic data

import MetricKit

for await report in manager.diagnosticReports {
    switch report.result {
    case .crash(let crash):
        let backtrace = crash.callStackTree
        let reason = crash.terminationReason
        let category = crash.terminationCategory
        processCrash(backtrace: backtrace, reason: reason, category: category)
    case .hang(let hang):
        processHangDiagnostic(hang)
    default: break
    }
}
Receive MetricKit data with states swift · at 13:57 ↗
// Receive MetricKit data with states

import MetricKit
import StateReporting

let domain = StateReportingDomain("com.metrickitsample.tabs")
let manager = MetricManager(enabledStateReportingDomains: [domain])


// Report transitions throughout the app

let reporter = StateReporter.reporter(for: domain.rawValue)
reporter.reportTransition(to: "Reports")
Define custom structured types swift · at 14:21 ↗
// Define custom structured types

import StateReporting

@ReportableMetadata
struct ViewConfiguration {
    let listSize: String
    let isSorted: Bool
}

let reporter = StateReporter.reporter(
    for: domain.rawValue,
    stableMetadata: ViewConfiguration.self
)

reporter.reportTransition(
    to: "Reports",
    stableMetadata: ViewConfiguration(listSize: "large", isSorted: false)
)
Send encoded metric reports to the server swift · at 15:29 ↗
// Send encoded metric reports to the server

import MetricKit

for await report in manager.metricReports {
    let encoder = JSONEncoder()
    
    let formatKey = MetricReport.encodingFormatKey
    encoder.userInfo[formatKey] = MetricReport.EncodingFormat.byStateReportingDomain
    
    let jsonData = try encoder.encode(report)
    sendToServer(jsonData)
}

Resources