Press ⌘B in Xcode. The first red bar in the Issue Navigator is the only Swift mistake you need to fix right now. Beginners often try to repair six errors at once; the compiler reports one bad line and then produces a pile of follow-on errors. Work top to bottom, rebuild after each change, and stop when the build succeeds. This is the order that keeps a first Swift project moving.
Start With the First Compiler Error, Not the Scariest One
Build with ⌘B and open the Issue Navigator with ⌘5. Read the message literally: Swift usually names the file, line, and expected type. Fix the topmost error first. If you see "Use of unresolved identifier 'usrName'," look for a typo or missing import. Swift is case-sensitive, so UserName and username are different names. After each change, build again; many later errors disappear when the first one is fixed.
Do not paste random code from a search result into the middle of your project. Click the error, let Xcode jump to the line, and change one thing. Swift does not need a semicolon at the end of every line, so a stray ; is rarely the fix. Save a clean build folder for later: Product > Clean Build Folder is Shift-⌘-K, not a first-aid step for every red error.
Correct Names, Types, and let Before Chasing Optionals
Three beginner mistakes dominate: a misspelled name, a mismatched type, and reassigning a constant. If Swift says "Cannot assign to value: 'score' is a 'let' constant," change let score = 0 to var score = 0 only if the value must change. If it should stay fixed, remove the assignment instead.
When Swift says "Cannot convert value of type 'Int' to expected argument type 'String'," convert explicitly with String(age) or "\(age)". Swift will not silently turn an Int into a String. For decimal math, remember that 5 / 2 is 2 when both values are Int; write Double(5) / 2 to get 2.5. These fixes are boring, but they clear a large share of first-project errors.
Fix Optionals With if let, guard let, or ??
Symptom: "Value of optional type 'String?' must be unwrapped." Cause: the variable may be nil. Fix: do not add ! by reflex. Use if let name = nickname { print(name) } when you need the value inside a block. Use guard let name = nickname else { return } when the function cannot continue without it. Use let displayName = nickname ?? "Guest" when a default is acceptable.
Force unwrapping with nickname! crashes at runtime if the value is nil. That is not a compiler error you can ignore; it is a crash waiting for the wrong tap or missing file. Dictionary lookups also return optionals, so let value = scores["Ana"] ?? 0 is safer than scores["Ana"]!. Treat ! as a warning sign unless you can prove the value exists at that exact moment.
Correct Array Indexes, String Indexes, and Loop Bounds
Symptom: "Fatal error: Index out of range" while the app is running. Cause: an array index is negative or greater than or equal to array.count. Valid array indices are 0..<array.count. Use for item in array, for (index, item) in array.enumerated(), or array.indices. Do not write array[array.count]; the last valid index is array.count - 1.
Loop bounds cause the same crash. for i in 0...array.count includes array.count and fails; use 0..<array.count. Swift String values are not indexed by Int, so name[0] does not compile. Use name.first, name.startIndex, name.index(after:), or name.firstIndex(of:). If you remove items while looping, iterate over a copy or collect the indices first.
Repair throws and Crashes With do-catch and the Debugger
Symptom: the compiler says "Call can throw, but it is not marked with 'try'" or the app stops on a line. Cause: a function is marked throws, so the call must use try inside a do block, or your own function must be marked throws. Fix it like this:
do {
let data = try String(contentsOfFile: path)
print(data)
} catch {
print("Read failed: \(error)")
}
Do not use try! for files, network responses, or user input; it turns a recoverable error into a crash. For a runtime crash, read the debug console message, then set a breakpoint on the line named in the crash. Use po variableName in LLDB to inspect values. If the variable is out of scope, you are paused in the wrong function.
Use Breakpoints and po Before Adding More print() Calls
When a value is wrong, click the gutter beside a line number to set a breakpoint, then run with ⌘R. When execution pauses, type po items.count or po name in the debugger console. Step through with the debug bar buttons rather than guessing where the value changed. print() is fine for a quick check, but remove debug prints before you call the fix finished.
If po reports "use of undeclared identifier," you are paused in a different scope than you think. Move the breakpoint closer to the line that uses the value. This habit catches optional nil values, empty arrays, and off-by-one counters faster than scattering ten print statements through the project.
Run a Clean Build and a Tiny Playground Test
After a fix, build with ⌘B and run with ⌘R. If the error persists, create a new Xcode Playground from File > New > Playground and paste only the failing expression. This isolates a language mistake from storyboard or app-lifecycle noise. Test one line, such as let scores = [10, 20]; print(scores[2]), then correct it to scores[1]. For a command-line check, swift --version confirms the compiler is available, and swiftc filename.swift compiles a single file without an Xcode project.
Use Shift-⌘-K only when old build products cause misleading errors, then build again. Delete experimental playground code before returning to the real project.
End With a Repeatable Fix Pass
Use the same order every time: first compiler error, names and types, let versus var, optionals, array and string indexes, throws handling, debugger inspection, then a tiny isolated test. This sequence keeps you from "fixing" follow-on errors that were never real mistakes. Rebuild after each change, and stop when the first error is gone.