I recently had a hunch that Samples was loading too many images at app launch. I had to figure out how to get a list of what images are loaded, no matter if the source is a Storyboard or a call to
Here’s how I did it, step by step:
- Bring up the Breakpoint Navigator (⌘7)
- Click the little + button in the bottom left corner
- Select Add Symbolic Breakpoint…
- Set up your breakpoint as shown above:
imageNamed:in the Symbol field
- Click Add Action, select Debugger Command
- In the command field, type
- Check Automatically continue after evaluating
- Run on device (⌘R)
Now all the names of images that are about to be loaded will be logged to the Debug Area. For added fanciness, you can select Debugger Output there, so your trace won’t be polluted by other log messages coming from your target.
For the curious:
po $r2 will print the Cocoa object pointed by the r2 register, which is where the first argument of an Objective-C message is stored - in our case, the name of the image to load. The value for
self is stored in r0, and the value for
_cmd (the selector to invoke) is stored in r1. Check out the documentation for
objc_msgSend and friends to learn more about the Objective-C runtime.
If there’s an easier way to accomplish this, let me know!