Debugging, Profiling and Code Quality

46.1 Debugging

Xcode breakpoints (conditional, symbolic, exception, logpoint actions), the LLDB console:

Xcode tools: the View Hierarchy Debugger, Memory Graph Debugger, the Thread Sanitizer (TSan), Address Sanitizer (ASan), Undefined Behavior Sanitizer, the Main Thread Checker, and SwiftUI's Self._printChanges().

Logging: the os.Logger unified logging system (Logger(subsystem:category:) with privacy levels), and swift-log for server/cross-platform use.

(lldb) po user                    # print object description
(lldb) p user.age                 # print with type info
(lldb) v                          # frame variables (fast, no code execution)
(lldb) expr user.name = "Ana"     # modify at runtime
(lldb) bt                         # backtrace
(lldb) br set -n viewDidLoad
import OSLog
let logger = Logger(subsystem: "com.example.app", category: "network")
logger.info("Fetching user \(userID, privacy: .private)")
logger.error("Request failed: \(error.localizedDescription)")

46.2 Profiling with Instruments

Time Profiler (CPU), Allocations and Leaks (memory), Swift Concurrency instrument (tasks, actors), SwiftUI instrument (view body evaluations), Network, Energy Log, Hangs, Core Animation. Use os_signpost / OSSignposter for custom intervals.

46.3 Code Quality Tools

swift-format (official, built into Swift 6 toolchains) Formatting and linting (swift format -i -r Sources)

Style and convention linting (rules, autocorrect) SwiftFormat (nicklockwood) Finds unused code SonarQube, Danger Swift CI quality gates and PR automation

-warnings-as-errors, upcoming features (ExistentialAny, InternalImportsByDefault, MemberImportVisibility)