Sometimes when debugging on Xcode with LLDB’s
po, it will throw a syntax error at you and you might be wondering out why? You checked for any typos but everything seems to be correct. So what gives?
Well, that’s because you might be using it in the wrong context.
Here’s a quick rundown:
When you stop in Objective-C code using breakpoint, LLDB will use Objective-C debugging context.
So you have to use Objective-C syntax to debug:
1(lldb) po [ViewController description]
Similarly when you add a breakpoint in Swift code, LLDB will use Swift debugging context instead.
So you have to use Swift syntax to debug:
1(lldb) po ViewController.description()
And finally, Xcode will always use Objective-C as the default context. Meaning if you pause the program execution without using breakpoint, you’ll have to use Objective-C syntax.
That’s it. Hopefully this tips will helps you a little bit when debugging a project that have a mixture of both Swift and Objective-C codes. ✌️