Swift version: 5.4
You’re probably already familiar with Xcode’s breakpoints, which allow you to pause code when a certain point is reached. Watchpoints also let you pause code, but their job is to pause when a variable is changed anywhere else in your code – it’s like a property observer, except implemented entirely using Xcode’s debugger.
To try it out, place a breakpoint in your program next to a variable you want to watch, then run your code. When the breakpoint hits, look for your variable inside the variables view – that’s in Xcode’s debug area at the bottom, to the left of the console.
When you find your variable, right-click on it and choose “Watch”. Once that’s done you can continue your program as normal, and anywhere the variable is read from or written to Xcode will pause and you can use the debug navigator to step through the call stack to figure out what happened.
SPONSORED From August 2nd to 8th you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Available from iOS
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.