For iOS developers, this is a really cool technique. Sometimes you want to see all the NSNotifications that get posted in your app, whether it is for debugging, or to see the timing of where listeners can be hooked in. Using breakpoints in Xcode will allow us to inspect the notifications.
Follow this procedure to set it up:
- In Xcode, open the breakpoints panel on the left sidebar.
- Click the + icon at the bottom left of the panel. Select “Add Symbolic Breakpoint…“
- Enter the following details:
- Click Add Action and enter the following details:
This prints out the 3rd parameter (internally speaking) — the name of the notification. The first two parameters if you’re curious are the NSNotificationCenter instance, and the command/message.
Updated June 7, 2015: If you are getting
error: use of undeclared identifier '$r2'try using
- Select “Automatically continue after evaluating“.
Your breakpoint settings should look like this:
You will then need to run the application on a device (sorry, this doesn’t work on the simulator). Note that if your application produces many notifications constantly, the speed of the application will be significantly slower, due to the breakpoints being processed. To work around this, you can disable the breakpoint until you get to the place where you want to analyze the notifications.