# Video Tutorial: Collection Views Part 1: Getting Started

**URL:** <https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136>\
**Category:** 🎓 Courses & Articles\
**Created:** [May 23, 2016, 2:06pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136 "2016-05-23T14:06:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![timmitra](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timmitra/32/108662_2.png) [@timmitra](https://forums.kodeco.com/u/timmitra)\
**Post date:** [May 23, 2016, 2:06pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/1 "2016-05-23T14:06:21Z")

</div>

In this video we look at the basics of Collection Views. We build a simple collection view displaying the index of each cell.

 
* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/3488-collection-views/lessons/2](https://www.raywenderlich.com/3488-collection-views/lessons/2)

---

<div class="post-metadata">

**Author:** ![mrpaulb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mrpaulb/32/81494_2.png) [@mrpaulb](https://forums.kodeco.com/u/mrpaulb)\
**Post date:** [May 26, 2016, 1:48pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/2 "2016-05-26T13:48:05Z")

</div>

Hi Tim,

At 13m45s near the end you removed the minimum spacing using size inspector for the UICollectionView. I also like to set properties for UI elements in code, so looked it up in the UICollectionViewFlowLayout [doc](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionViewFlowLayout_class/). Just need to add the following to the end of MasterViewController viewDidLoad:

`layout.minimumInteritemSpacing = 0`

Thanks for making the video, I can see this is going to be of much use for me.

Paul

---

<div class="post-metadata">

**Author:** ![mrpaulb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mrpaulb/32/81494_2.png) [@mrpaulb](https://forums.kodeco.com/u/mrpaulb)\
**Post date:** [May 26, 2016, 2:26pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/3 "2016-05-26T14:26:53Z")

</div>

Hi Tim, In the challenge solution there is some nesting of if let in the prepareForSegue. I had a go at flattening this with guard let :

```
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "MasterToDetail" {
      guard let indexPath = collectionView?.indexPathsForSelectedItems()?.first! else { return }
      guard let paper = papersDataSource.paperForItemAtIndexPath(indexPath) else { return }
      let detailViewController = segue.destinationViewController as! DetailViewController
      detailViewController.paper = paper
    }
  }

```

Appears to work fine, I’m not so experienced with doing this. Would appreciate the wisdom of others, if this looks good or not.

Paul

---

<div class="post-metadata">

**Author:** ![saijithendra](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/saijithendra/32/108550_2.png) [@saijithendra](https://forums.kodeco.com/u/saijithendra)\
**Post date:** [June 10, 2016, 6:14pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/4 "2016-06-10T18:14:07Z")

</div>

Hello Tim,

In this video, you set minimum spacing and all = 0. Then, could you explain me how did we get the white spacing in between the cells ?

---

<div class="post-metadata">

**Author:** ![timmitra](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timmitra/32/108662_2.png) [@timmitra](https://forums.kodeco.com/u/timmitra)\
**Post date:** [June 11, 2016, 9:16pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/5 "2016-06-11T21:16:12Z")

</div>

It’s true that we set the minimum spacing between the cells themselves to be 0. That means that we really are butting them together with no space between them.

If you go back to around 6:30 in the video, you might recall that we centered a green UIView in the prototype cell. We also sized the UIView with AutoLayout constraints of 2 points (with Constrain to Margins unchecked.)

That makes the UIView smaller than the CollectionView cell by 4 points. So we end up with 2 points of white space around the views. That creates the white space that you see.

---

<div class="post-metadata">

**Author:** ![timmitra](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timmitra/32/108662_2.png) [@timmitra](https://forums.kodeco.com/u/timmitra)\
**Post date:** [June 11, 2016, 10:38pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/6 "2016-06-11T22:38:23Z")

</div>

That looks good. You can sometimes gang the conditions together, on one line in the guard. That way you can create the deatilViewController only if the both of the conditions are met.

Try this:

`override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "MasterToDetail" { guard let indexPath = collectionView?.indexPathsForSelectedItems()?.first, paper = papersDataSource.paperForItemAtIndexPath(indexPath) else { return nil } let detailViewController = segue.destinationViewController as! DetailViewController detailViewController.paper = paper } } `

---

<div class="post-metadata">

**Author:** ![amitai](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/amitai/32/38910_2.png) [@amitai](https://forums.kodeco.com/u/amitai)\
**Post date:** [August 15, 2016, 2:59pm UTC](https://forums.kodeco.com/t/video-tutorial-collection-views-part-1-getting-started/15136/7 "2016-08-15T14:59:32Z")

</div>

Hi, there’s a bug in the Resources, on `PapersDataSource.swift`, line 142, it has:

```
if sections.contains(section) {
    sections.append(section)
}

```

And it should be:

```
if !sections.contains(section) {
    sections.append(section)
}

```

The error is fixed in the resources on Part 3, but in the resources up until then, it’s not…
