Master Xcode project structure, simulators, debugging tools, and Instruments.
Xcode Workflow
# Xcode 15+ required for iOS 17 development
# Check version: xcodebuild -versionProject Structure
MyApp/
├── MyApp.xcodeproj/ # Project file (legacy)
│ └── project.pbxproj
├── MyApp.xcworkspace/ # Workspace (for CocoaPods/SPM)
├── MyApp/ # Main target
│ ├── Assets.xcassets/ # Images, colors, app icons
│ ├── Base.lproj/ # Storyboards (if any)
│ │ └── LaunchScreen.storyboard
│ ├── Info.plist # App configuration
│ ├── MyApp.entitlements # Capabilities
│ ├── Preview Content/ # SwiftUI previews
│ │ └── Preview Assets.xcassets
│ ├── Models/ # Data models
│ ├── Views/ # SwiftUI views
│ ├── ViewModels/ # MVVM view models
│ ├── Services/ # Network, persistence
│ ├── Helpers/ # Extensions, utilities
│ └── Resources/ # Fonts, JSON, certificates
├── MyAppTests/ # Unit tests
└── MyAppUITests/ # UI tests
Project Settings
# General
# - Display Name, Bundle Identifier, Version, Build
# - Deployment Target (iOS 16.0+)
# - Supported Destinations (iPhone, iPad, Mac)
# Signing & Capabilities
# - Automatically manage signing (recommended)
# - Team selection
# - Capabilities: Push Notifications, Sign In with Apple, etc.
# Build Settings
# - Swift Language Version: Swift 5
# - Optimization Level: -O (release), -Onone (debug)
# - Dead Code Stripping: Yes
# - Enable Bitcode: No (deprecated)Swift Package Manager
// Package.swift (for local packages)
// Or use Xcode: File → Add Package Dependencies
// Common packages:
// - https://github.com/realm/SwiftLint
// - https://github.com/pointfreeco/swift-composable-architecture
// - https://github.com/Alamofire/Alamofire
// - https://github.com/SDWebImage/SDWebImageSwiftUI// Adding via Package.swift
dependencies: [
.package(url: "https://github.com/realm/SwiftLint", from: "0.54.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.0.0"),
]
// Target dependencies
.target(
name: "MyApp",
dependencies: [
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
)Simulators
# List simulators
xcrun simctl list devices
# Create simulator
xcrun simctl create "iPhone 15 Pro" "iPhone 15 Pro" "iOS 17.2"
# Boot simulator
xcrun simctl boot "iPhone 15 Pro"
# Install app
xcrun simctl install booted /path/to/MyApp.app
# Launch app
xcrun simctl launch booted com.example.myapp
# Erase simulator
xcrun simctl erase "iPhone 15 Pro"
# Simulator screenshots
xcrun simctl io booted screenshot screenshot.png
# Record video
xcrun simctl io booted recordVideo video.movDebugging
// Breakpoints
// - Click line number to add
// - Right-click → Edit Breakpoint → Add Action
// - Conditions: self.count > 10
// LLDB Commands
// (lldb) po variable // Print object description
// (lldb) p variable // Print raw value
// (lldb) bt // Backtrace
// (lldb) frame variable // All local variables
// (lldb) expr var = 5 // Modify value
// (lldb) continue // Continue execution
// Debug Navigator
// - Threads & stacks
// - Variables view
// - Console output
// View Debugging
// Debug → View Debugging → Capture View Hierarchy
// - Inspect view hierarchy in 3D
// - Check constraints, layout
// - Find clipped views
// Memory Graph Debugger
// Debug → Memory Graph
// - Detect retain cycles
// - See reference counts
// - Filter by leakedLogging
// OSLog (recommended)
import OSLog
private let logger = Logger(subsystem: "com.example.myapp", category: "network")
logger.info("Request started: \(url)")
logger.debug("Response: \(response, privacy: .private)")
logger.error("Failed: \(error, privacy: .public)")
logger.fault("Critical: \(error)")
// Privacy levels
// .public - always shown
// .private - redacted in release
// .sensitive - never shown
// Signposts (performance)
let signposter = Signposter(logger: logger)
let state = signposter.beginInterval("Network Request")
defer { signposter.endInterval("Network Request", state) }
// Print (debug only)
#if DEBUG
print("Debug: \(variable)")
#endif
// SwiftUI debug
Text("Hello")
.background(Color.red) // Visual debug
.border(Color.blue)Instruments
# Launch from Xcode: Product → Profile (Cmd+I)
# Or command line:
xcrun instruments -t "Time Profiler" -D trace.trace MyApp.app
# Key Instruments:Time Profiler
# CPU usage, call trees
# - Find hot paths
# - Identify main thread blocking
# - Invert call tree to find root causes
# Tips:
# - Run on device (simulator differs)
# - Profile release build
# - Look for "self weight" - time in function itselfAllocations
# Memory allocations, leaks
# - Track object creation/destruction
# - Mark generations (heapshots)
# - Find abandoned memory
# - Check for retain cyclesLeaks
# Detect leaked memory
# - Runs static analysis + runtime
# - Shows leaked objects with backtraces
# - Fix: use weak/unowned referencesNetwork
# Network connections
# - Request/response timing
# - Connection reuse
# - Cellular vs WiFi
# - Request/response sizesEnergy Log
# Energy impact
# - CPU, GPU, network, location
# - High energy spikes
# - Background vs foregroundCore Animation
# Rendering performance
# - FPS, commit times
# - Offscreen rendering
# - Color misaligned images
# - Blended layersCustom Instruments
# Create custom: File → New → Custom Instrument
# Use os_signpost for custom metricsBuild Configurations
// Configs/Debug.xcconfig
#include "Base.xcconfig"
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG
ENABLE_TESTABILITY = YES
GCC_OPTIMIZATION_LEVEL = 0
SWIFT_OPTIMIZATION_LEVEL = -Onone
// Configs/Release.xcconfig
#include "Base.xcconfig"
SWIFT_ACTIVE_COMPILATION_CONDITIONS = RELEASE
ENABLE_TESTABILITY = NO
GCC_OPTIMIZATION_LEVEL = s
SWIFT_OPTIMIZATION_LEVEL = -O// Base.xcconfig
SWIFT_VERSION = 5.9
IPHONEOS_DEPLOYMENT_TARGET = 16.0
CODE_SIGN_STYLE = Automatic
DEVELOPMENT_TEAM = YOUR_TEAM_IDSchemes
# Product → Scheme → Manage Schemes
# - Shared: check for CI
# - Build configurations per action:
# Run: Debug
# Test: Debug
# Profile: Release
# Analyze: Debug
# Archive: Release
# Environment variables in scheme:
# - OS_ACTIVITY_MODE = disable (reduce console noise)
# - SWIFTUI_DEBUG = 1 (SwiftUI debug info)Continuous Integration
# .github/workflows/ios.yml
name: iOS CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-and-test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_15.2.app
- name: Install dependencies
run: |
# SPM resolves automatically
# For CocoaPods:
# pod install
- name: Build
run: |
xcodebuild build \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2' \
-quiet
- name: Test
run: |
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2' \
-enableCodeCoverage YES \
-quiet
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: ./coverage.xcresultUseful Shortcuts
# Build: Cmd+B
# Run: Cmd+R
# Test: Cmd+U
# Profile: Cmd+I
# Clean: Cmd+Shift+K
# Clean Build Folder: Cmd+Option+Shift+K
# Open Quickly: Cmd+Shift+O
# Show Document Items: Cmd+Ctrl+J
# Find Navigator: Cmd+Shift+F
# Debug Navigator: Cmd+7
# Breakpoint Navigator: Cmd+8
# Report Navigator: Cmd+9
# Assistant Editor: Cmd+Option+Return
# Show/Hide Inspectors: Cmd+Option+1/2/3/4/5
# Show/Hide Navigators: Cmd+0
# Show/Hide Debug Area: Cmd+Shift+YTry It
Create a project. Add Swift Package. Set breakpoint. Profile with Time Profiler. Fix a memory leak. Run tests in CI.
# Xcode → New Project → iOS App
# Add package: File → Add Package Dependencies
# Profile: Product → Profile → Time ProfilerXcode proficiency
- Create project with SPM dependency
- Configure Debug/Release xcconfig files
- Add shared scheme for CI
- Write unit test and run with coverage
- Profile app with Time Profiler - find slow function
- Use Memory Graph to detect retain cycle
- Set up GitHub Actions for iOS build/test
Xcode is powerful but complex. Master: project structure, schemes, xcconfigs, simulators, debugging (breakpoints, LLDB, view debugger), Instruments (Time Profiler, Allocations, Leaks). Automate with xcodebuild and GitHub Actions. Profile on device, not simulator.
Resources
- Xcode Documentation: https://developer.apple.com/xcode/
- Instruments Guide: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/
- xcodebuild Reference: https://developer.apple.com/documentation/xcodebuild
- Swift Package Manager: https://www.swift.org/package-manager/