Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - is it possible to debug crashes in the Interface Builder's Live Rendering process (IBDesignable)?

Tags:

Question

Is it possible to set breakpoints and debug code executed by Xcode / Interface Builder's Live Rendering? That is, I am using the IBDesignable and IBInspectable attributes to affect the view as it is rendered in an interface builder storyboard, and would like to be able to debug "IB crashed" errors. I don't recall this from the WWDC session, other than the section on prepareForInterfaceBuilder.

Context

I recently started seeing a number of errors reporting that IB crashed when attempting to render my code. I ultimately traced it to an otherwise innocent line of code in layoutSubviews in one of my views that was linked from the storyboard. The specific problem that IB - when rendering live views, called layoutSubviews before setting all the view's child view properties (which seems like a separate problem, in and of itself). This contrasted with the simulator and device, in which the views were set ahead of the first call to layoutSubviews. Long story short though, it involved diffing a bunch of files to find the offending change. Suffice to say, I could have found the problem quickly if it were possible to set breakpoints and trap the crash.

Has anyone figured out how to debug and/or generally trap these problems, or is that access not yet available?

like image 736
Chris Conover Avatar asked Oct 14 '14 18:10

Chris Conover


People also ask

Does Xcode have a debugger?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

How do I run debugger in Xcode?

Step Through Code in the Debugger Customize what Xcode displays when running your app in the debugger by choosing Xcode > Preferences > Behaviors > Running. Use the buttons in the debug bar to control the execution of your app.

What is debug in Swift?

Integrated debugging. The most obvious benefit is that the Swift REPL is also a full-featured debugger. It's trivial to declare a function, set a breakpoint in it, and then call it. When execution stops at a breakpoint the full feature set of the debugger is immediately available.


1 Answers

I watched the WWDC video again (§411 @22:00 or so). You have to

  • edit a view in IB, and set its custom class to a class in your codebase
  • set breakpoints as desired in your custom class
  • select the view in IB, then select Editor -> "Debug Selected Views" (at bottom)

Oddly, in my tests today, it is creating my view via (initWith)Frame instead of (initWith)Coder. This causes subsequent constraint configuration logic to fail as the sub views have not been set (as they would had 'withCoder been called).

like image 199
Chris Conover Avatar answered Oct 05 '22 11:10

Chris Conover