Debugging iOS with LLDB in Swift - The PO command
Hello ladies and gentlemen, Leo here.
Today we'll start to talk one option to help you debug your iOS/Swift code.
LLDB is a next generation, high-performance debugger. It is built as a set of reusable components which highly leverage existing libraries in the larger LLVM Project, such as the Clang expression parser and LLVM disassembler. The project link
LLDB is the default debugger in Xcode on macOS and supports debugging C, Objective-C and C++ on the desktop and iOS devices and simulator.
Let's explore one thing you can use to debug in lldb, the command:
You have a breakpoint and a very complex class/struct with a lot of attributes, or want to know what is the value of a Nth item in a collection.
First you'll have to put a breakpoint somewhere in the scope you're looking for. Then, when the breakpoint stop the app you will be able to see on the console the lldb line has appeared. In the example below we are trying to inspect what are the name of the 9384 in runtime. You can inspect any attribute or variable within the scope. This is really useful because with just one breakpoint you can get ALL information you need to debug!
Now you just put what are you looking for, in this case
po personList //the 9384th person in the list
You can use de PO command for anything you want to get from your scope. So the next time you are debugging, you can use this tool to help you to get everything you need to achieve your goal!
This is just a tiny tiny bit of the lldb power and we'll continue to share more useful command in future posts.
Thanks for the reading and... That's all folks!