Mastering Auto Layout - Part 5: UILayoutGuide | Ray Wenderlich Videos

Instead of using empty views to control the spacing of views, when you're not using Stack Views, you can use UILayoutGuides!

This is a companion discussion topic for the original entry at

I got completely lost here.

no idea what .map really does or why it’s needed. Then suddenly we are knee deep in closures which is a difficult topic. Then the foreach with view.addlayoutguide, I completely lost track what is happening.

Coupled with the scrollview in the next lesson which is a later part of the course which we didn’t take yet, this is not well paced.

Hi farisb!

This transforms UIImages into UIImageViews:

let imageViews: [UIImageView] = {image in
  let imageView = UIImageView(image: image)
  imageView.translatesAutoresizingMaskIntoConstraints = false
  return imageView

And this creates a certain number of UILayoutGuides, based on how many images there are:

let spacerGuides = (0..<images.count - 1).map {_ in UILayoutGuide()}

You can find a refresher on map, here: Programming in Swift · Closures and Collections

Thank you for the feedback. We’re aware that it’s too advanced to be in the learning path, where it is, and are working to improve the learning path flow!

Thank you Jessy. Will take another go at it.