Tony Stark Tony Stark - 8 months ago 52
Swift Question

how to observer variable value changes over time in xcode

I'm currently learning ios developement using swift and I was just wondering if there is a way in xcode to

1) set a breakpoint on a variable whenever the value of the variable changes


2) somehow track the change to variable value over time


Method with Swift didSet and willSet

You can use the print in the console:

class Observable {
    static var someProperty: String? {
        willSet {
            print("Some property will be set.")
        didSet {
            print("Some property has been set.")

Method with watchpoints

Watchpoints are a tool you can use to monitor the value of a variable or memory address for changes and trigger a pause in the debugger when changes happen. They can be very helpful in identifying problems with the state of your program that you might not know precisely how to track down.

You can find a great guide here