Search code examples
iosxcodeswiftswift-playground

How to get a layout Trace in a Swift Playground


Im prototyping some Views in a Swift Playground.

import UIKit
import XCPlayground

let containerView = UIView(frame: CGRect(origin: CGPointZero, size: CGSize(width: 320, height: 300)))

XCPShowView("Container View", containerView)

I am using this Container View to throw in some Views and Layout them with Constraints. Now i would really like to get a LayoutTrace from it, like the one from

po [[UIWindow keyWindow] _autolayoutTrace]

This would allow me to easily find some Ambiguous Layout.

Any Ideas?


Solution

  • You can use the Objective-C runtime's valueForKey to access _autolayoutTrace from a Swift Playground:

    print(containerView.valueForKey("_autolayoutTrace"))