Question: I'm developing an iOS app which includes Facebook Login, I have done the login button, but going through the Facebook Test I saw a test to ensure token validity, and if not valid, ask the user to sign in again, I would like to know how to check if a Access Token is valid or expired using Swift 3.0.

Answer: 
I think this will work.

```
override init(collectionViewLayout layout: UICollectionViewLayout) {
    super.init(collectionViewLayout: layout)
    collectionView?.collectionViewLayout = YourCollectionViewLayout()
}

```
I resolved this issue taking these steps:

1 - Changing UICollectionViewController to a UIViewController with a collectionView inside.

2 - On ViewDidLoad I set the delegates and add the view, as usual. Moreover, I instantiate the ViewLayout and use it to instantiate the CollectionView

```
  var collectionView: UICollectionView?

override func viewDidLoad() {
super.viewDidLoad()

navigationController!.isToolbarHidden = true

let layout = MosaicViewLayout()
layout.delegate = self

collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)

guard let collectionView = collectionView else {
  return
}

view.addSubview(collectionView)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(PhotoCell.self, forCellWithReuseIdentifier: "CharacterCell")
setupCollectionConstraints()

```

}

3 - On the ViewLayout the protocol stays like this:

```
protocol MosaicViewLayoutDelegate:class {

func collectionView(_ collectionView: UICollectionView,
                  heightForItemAtIndexPath indexPath: IndexPath) -> CGFloat
}

```

Don't forget to add the instance inside the class

```
  weak var delegate: MosaicViewLayoutDelegate?

```

4 - Add the delegate extension to you ViewController

```
extension HomeViewImpl: MosaicViewLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, heightForItemAtIndexPath indexPath: IndexPath) -> CGFloat {
let random = arc4random_uniform(4) + 1
return CGFloat(random * 100)
 }
}

```

enter code here