Is it possible to set watchpoints on Swift properties?

The answer was much simpler than I imagined. The easiest way to do this is to simply add a breakpoint on the property declaration. The debugger will break whenever the property is either read or written.

If, like me, you want to break only when the property is changed and ignore fetches, set a breakpoint on the property declaration, then go into the LLDB console and type "br list" to see a list of all your breakpoints:

(lldb) br list
Current breakpoints:
1: file = '/Users/testuser/Desktop/TestFoo/Test.swift', line = 12, locations = 3, resolved = 3, hit count = 1

  1.1: where = TestFoo`TestFoo.Test.x.getter : Swift.Int + 12 at Test.swift:12, address = 0x00000001084cfefc, resolved, hit count = 1 
  1.2: where = TestFoo`TestFoo.Test.x.setter : Swift.Int + 16 at Test.swift:12, address = 0x00000001084cff80, resolved, hit count = 0 
  1.3: where = TestFoo`TestFoo.Test.x.materializeForSet : Swift.Int + 16 at Test.swift:12, address = 0x00000001084d00f0, resolved, hit count = 0 

As you can see, there's a master breakpoint "1" with three sub-breakpoints. Disable the sub-breakpoint for the getter:

(lldb) br disable 1.1
1 breakpoints disabled.

and you're all set. The debugger will break only when that property is modified.


On XCode (8.2 Swift 3.0) set breakpoint normally on the swift property then run your app. After the app has ran go to breakpoint panel you can expand the breakpoint into multiple breakpoints:

enter image description here

All are selected by default, you can then disable the ones you don't need. NOTE: I found when you first add the breakpoint it will not expand until you run the app.

An alternative method you can try is to use lldb to add them. First add breakpoint somewhere inside your class instance eg viewDidLoad ext. p self and note the memory address of your instance.

Then add breakpoint like so where 0x0f0f0f0f0f0f is memory address of your object.

break set -F '-[MyClass setMyProperty:]' -c '$rdi == 0x0f0f0f0f0f0f'