Debugging Views in XCode with Swift / LLDB

Borama Apps
Apr 29 · 2 min read

During execution of your project press “Debug View Hierarchy” button.

We’ll be using swift so instead of using all the time

expr -l Swift --

alias it using:

command alias se expr -l Swift --

import UIKit:

po @import UIKit

Import the project:

expr -l Swift -- import VideoDelaySwift

or using alias:

se import VideoDelaySwift

Select problematic view and print description of this view using ie:

<VideoDelaySwift.BufferedView: 0x14e84fe0; frame = (0 0; 320 568); autoresize = RM+BM; layer = <CALayer: 0x14e83fa0>>

Let’s assign the view to variable:

se let $bv = unsafeBitCast(0x14e84fe0, VideoDelaySwift.BufferedView.self)

Now we can access the object ie:

se print($bv.layer.subLayers)se print($bv.baseScale)

We can also access AppDelegate and displayed view controller using:

To access AppDelegate print description of root UIWindow:

<UIWindow: 0x14e66f40; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x14e61b00>; layer = <UIWindowLayer: 0x14e50bc0>>
po [0x14e66f40 nextResponder]
<UIApplication: 0x14d61a50>
po [0x14d61a50 nextResponder]
<VideoDelaySwift.AppDelegate: 0x14d64a70>
se let $ad = unsafeBitCast(0x14d64a70, to: VideoDelaySwift.AppDelegate.self)

To access current ViewController and access it’s members print description of root UIView:

Printing description of $276:<UIView: 0x14d97400; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x14d974e0>>
po [0x14d97400 nextResponder]
se let $vc = unsafeBitCast(0x14d7d600, to: VideoDelaySwift.ViewController.self)
se print($vc.controlsView)
Optional(<VideoDelaySwift.ControlsView: 0x14d80cc0; frame = (0 0; 70 500); autoresize = RM+BM; layer = <CALayer: 0x14d95cb0>>)

That’s it!

Full repository:

Please check my IOS and Android apps!

Follow me on twitter :)

Borama Apps

Written by

ios, android, web apps.,

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade