All Articles

Looping through subviews and downcasting in Swift

I’ve been playing around with Auto-Layout. This snippet was helpful to see what constraints were set on what views in my View Hierarchy.

Getting the downcast right on the subviews Array took a few tries:

func showAL(view: UIView) {
    println("!")
    println(view)
    println(view.constraints())
}

    for view in self.subviews as [UIView] {
        showAL(view)
        for subview in view.subviews as [UIView] {
            showAL(subview)
        }
    }
    ```
Published 22 Jul 2014

Code. Comics. Crossfit
Tim Broder on Twitter