iOS Dev Nugget 166 @expr import UIKit


Need to run a code review on your codebase? Hire me

Ever set a breakpoint in a Obj-C project, run this:

(lldb) po UIScreen.mainScreen.bounds

and get:

error: property 'bounds' not found on object of type 'id'
error: 1 errors parsing expression

Annoying isn't it?

You can fix this by doing:

(lldb) expr @import UIKit

So run po UIScreen.mainScreen.bounds again, and you'd get:

(origin = (x = 0, y = 0), size = (width = 414, height = 736))

But you have to do this manually everything you start a debug session. As a good programmer and fan of automation, you can set a breakpoint and let Xcode do it for you.

  1. Cmd+7 to show the Breakpoints navigator
  2. Add a symbolic breakpoint for the symbol UIApplicationMain
  3. Add an action for that breakpoint: expr @import UIKit
  4. Check that so it automatically continues after evaluating actions

Now every time you run the project, commands such as po UIScreen.mainScreen.bounds will work.

Bonus nugget:

Ctrl-click on your breakpoint in the Breakpoints navigator. Choose Move BreakPoint To, and choose User. This will make the breakpoint available for every Xcode project (enabled by default).

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No



Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter


View archives of past issues