reveal是一款可以查看iOS app各个元素层次结构的工具,以前的查看方法,需要将reveal的framework嵌入到iOS工程里面,如果工程代码发生变更,需要先删掉导入的framework,将工程代码pull到本地,再将reveal framework导入,非常麻烦。
最近reveal对此种模式进行了改变,改进后的方法如下:
So you use Reveal and you love it. But you’ve just fired up a new app in Xcode’s debugger and you want to have a quick look at the internals of the app’s view hierarchy, but you haven’t integrated Reveal via the static or dynamic library yet. What to do?
No problem! LLDB to the rescue.
LLDB can execute arbitrary code inside your running application. So you can just load Reveal into any iOS process you are currently debugging.
Just hit ^⌘Y to pause the iOS app in the Xcode debugger and then at the (lldb)
prompt type:
Simple, right?
OK, so maybe not so simple and easy to remember. Wouldn’t it be better if we could just type reveal_load
at the LLDB prompt or something like that?
Well, we can! LLDB supports command aliases. Just like with bash, you can create an alias in LLDB for a more complex command. The syntax is a bit different but the concept is the same. Also, just like bash, LLDB has a ‘dot file’ that it loads every time it starts which is the ideal place to put your LLDB command alises. That dot file is ~/.lldbinit
.
Open up your favourite text editor, create the file .lldbinit
file in your home directory and chuck the following LLDB command aliases into it:
The above snippet creates four command aliases: reveal_load_sim
, reveal_load_dev
, reveal_start
and reveal_stop
.
reveal_load_sim
assumes that you’ve installed Reveal into your system’s standard /Applications
folder and reveal_load_dev
assumes you have added the Reveal dylib to your application’s Copy Resources build phase. Yes, I was fibbing a little about not having to modify your Xcode project. Sorry.
With these aliases defined you can now issue these quick commands at the LLDB prompt in Xcode. LLDB even auto-completes them for you!
Note that the reveal_load_dev
command alias will work with the iOS Simulator too, but it requires libReveal.dylib
be bundled in your application as a resource. See the Reveal Integration Guide (in Reveal’s help menu) for more information on using the Reveal dylib.
Ok so now you have some quick LLDB command aliases and can trigger them manually, how do you make it more automatic?
Breakpoints!
Xcode (LLDB really) can execute commands in response to breakpoints. Using this knowledge we can add breakpoints to our application that load and start Reveal automatically.
The image above shows how you can add the Reveal LLDB commands to a break point in Xcode.
Some things to note about this breakpoint:
- The break point is set to continue automatically so that the debugger doesn’t stop your app from executing when it loads Reveal.
- Both the load and start commands are being executed. If you place your breakpoint in (or before)
application:didFinishLaunchingWithOptions:
you don’t have to actually issue thereveal_start
command. Reveal automatically listens forUIApplicationDidFinishLaunchingNotification
and starts automatically when this notification is fired by an app. There is no harm in trying to start Reveal twice. You might just see duplicate log messages.
When the breakpoint commands are successfully executed by LLDB you will see something like the following in the debugger console:
Now you’re armed with LLDB and Reveal super powers!