Beginning Collection Views - Part 2: Getting Started | Ray Wenderlich

Learn about the most important components of collection views; the controller, the layout, and the data source.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3819-beginning-collection-views/lessons/2

Where can I find the starter project for lesson 2?

The materials have been updated to include the sample projects. Thanks for bringing this to our attention! :]

Michael, do you happen to have the swift 2.2 version of this code?
(I need to make it work in 7.3.1)
I converted most of it however, I am having trouble in understanding what I should be changing in PerksDataSource.swift.
It won’t recognize IndexPath as a type.

Instead IndexSize you need to use (in MasterViewController.swift):

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = view.frame.width/3
return CGSize(width: width, height: width)
}
And class MasterViewController will look like this:
class MasterViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout{

}

Instead IndexSize you need to use (in MasterViewController.swift):

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = view.frame.width/3
return CGSize(width: width, height: width)
}
And class MasterViewController will look like this:
class MasterViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout{

}

Hey everyone :slight_smile: was just wondering if you have the swift 3 version of this code? I am getting errors in my MasterViewCollection file. Around the step at 5:58 in part 2 video. See dropbox link: https://www.dropbox.com/s/fl2yoewfqzlrpav/Screen%20Shot%202017-03-17%20at%201.53.42%20pm.png?dl=0

Thank you so much for your help!!

Hi,
I think you need to add “return cell”~~
This error means that you need return UICollectionViewCell for this function.

cell.textLabel does not exist for collection view cells.

  1. how are you accessing it?
  2. what is the alternative?

@skyrocketsw Can you please help with this when you get a chance? Thank you - much appreciated! :]