Capstone: A Complete Workflow From New Project to a Debugged, Profiled Build

Xcode: The IDE Itself

Chapter 9 ยท Capstone: A Complete Workflow From New Project to a Debugged, Profiled Build

This chapter puts the whole course to use in one continuous workflow: start a project, organize it, design a view, commit, find a bug, clean up the code, and then run and profile the result. Every step points back to the chapter that supplies its tool. It adds no new tools.

Read This First: Nothing Here Was Run
I wrote this course on a machine without Xcode, so I have not run any step of this workflow, compiled the Swift below, or seen the results of the debugger or Instruments sessions. Every step is composed from the earlier chapters' sources, and those chapters mark which parts came from dated or third-party material. Treat this chapter as a checklist to follow and verify in your own Xcode, not as a record of something that was done.

The Workflow, Step by Step

Step 1: Check Your Tools (Chapter 1)

Confirm your Xcode version before anything else, since menus and features move between releases. Chapter 1 named Xcode 27 as the latest version when this course was written.

xcodebuild -version

Step 2: Create the Project and Its Repository (Chapters 2 and 8)

Create a new iOS app project. During setup, Chapter 8 noted a checkbox for creating a Git repository. Afterwards, identify the pieces from Chapter 2: the project, its app target, and the scheme with its Debug and Release configurations. Decide with anyone you work with which files go into version control, since Chapter 8 could not give a verified list.

Step 3: Add a Dependency and a Linter (Chapters 2 and 7)

Add SwiftLint as a package through File → Add Package Dependencies, or through its build tool plugin, which its repository describes as recommended for modern projects. Keep the default "Up to Next Major" rule unless you have a reason not to. Check the Package Dependencies in your project rather than assuming where Package.resolved ended up, because Chapter 2 could not verify that.

Step 4: Build a View and Preview It (Chapter 3)

Write the view below and open the canvas with Option + Command + Return. It contains a deliberate bug, a function that should total a list of scores but skips the first one. It is written to be valid Swift, but I did not compile it.

import SwiftUI struct ScoreView: View { let scores = [10, 20, 30] var body: some View { Text("Total: \(total(scores))") } func total(_ scores: [Int]) -> Int { var sum = 0 for index in 1..<scores.count { sum += scores[index] } return sum } } #Preview { ScoreView() }

The preview should show a total of 50, not the expected 60, because the loop starts at index 1. Notice that nothing crashes. That is the kind of bug the debugger is for.

Step 5: Commit the Starting Point (Chapter 8)

Stage and commit the project. In Xcode 15 and later you must explicitly stage changes before committing. Write a commit message that says the view has a known bug, so the history records it.

Step 6: Find the Bug (Chapter 4)

Run the app in the Simulator (Chapter 6) and put a breakpoint on the line sum += scores[index]. Make it conditional, so it stops only on the last iteration, then use the console.

# When execution pauses on the conditional breakpoint: p sum p index po scores bt

You should see that sum is 50 on the final iteration and that the loop never used scores[0]. The fix is to loop over all indexes.

Step 7: Fix and Clean Up (Chapter 7)

Correct the loop, then use Refactor → Rename to give the function a clearer name, and Refactor → Extract to Method if you split it further. Run Product → Analyze, keeping in mind Chapter 7's caution that its coverage of pure Swift is unverified, and run SwiftLint. Commit again, and check the diff first.

Step 8: Run on the Right Target, Then Profile (Chapters 5 and 6)

Run on the Simulator for quick checks and on a real device for anything the Simulator cannot show. Then profile from a Release build with Product → Profile. For a screen this small, Time Profiler would show little, and that is a result too: it tells you there is nothing to fix. For a real app, use Allocations to watch Persistent Bytes while repeating an action, and Leaks with its Cycles & Roots view, remembering Chapter 5's note that Leaks may miss a cycle that a live object still references.

Which Chapter Supplied What

StepChapterTool or fact used
11: What Xcode Actually IsVersion check with xcodebuild -version
22: Project Structure & the Build SystemProject, target, scheme, Debug and Release
32 and 7Swift Package Manager rules; SwiftLint installation
43: Interface Builder & SwiftUI Previews#Preview and the canvas
5 and 78: Source Control IntegrationStaging, commit, diff
64: The Console & Basic DebuggingConditional breakpoint; p, po, bt
77: Code Inspection & Refactoring ToolsRename, Extract to Method, Analyze, SwiftLint
85 and 6Instruments; Simulator versus a real device
A Habit This Course Kept Returning To
Almost every chapter ended up saying that some detail was dated, third-party or unverified, and that you should check it in your own Xcode version. The strongest skill this course can give you is not a menu path but that habit: identify the version, identify the age of the source, and test the claim.

What This Course Did Not Cover

  • Xcode Cloud in depth (see iOS Development — Production & Publishing 9).
  • Testing tools such as Swift Testing and XCTest as Xcode features (see iOS Development — Architecture & Data 6 and 7).
  • The coding agents and Device Hub that Apple's page lists for Xcode 27.
  • Storyboards, and any Interface Builder workflow beyond its history.
  • Newer instruments such as the SwiftUI instrument, which iOS Development — Production & Publishing 3 covers.

Hands-On Exercises

Exercise 1

In your own Xcode, create the project and view from Steps 2 to 4. Report what the preview shows, and write down your Xcode version and anything that differed from this chapter's description.

๐Ÿ“„ View solution
Exercise 2

Using a conditional breakpoint and the console commands, find the reason the total is 50 and not 60. Say which values you inspected and what they showed.

๐Ÿ“„ View solution
Exercise 3

Write a one-page checklist for a teammate that covers all eight steps, marking for each step which chapter it comes from and which claim you verified yourself in your own Xcode.

๐Ÿ“„ View solution

Chapter 9 Quick Reference

  • Workflow: check version, create project and repository, add package and linter, build and preview, commit, debug, fix and clean up, run and profile
  • Debugger: conditional breakpoint plus p, po, bt
  • Profiling: Product → Profile builds a Release build; Allocations for growth, Leaks for cycles
  • Not run: the whole workflow and the sample code were written without Xcode available

Course Complete

This closes Xcode: The IDE Itself, the fourth course in the iOS Development Subject alongside iOS Development Fundamentals, Architecture & Data, and Production & Publishing.