 extension MediaViewController: UICollectionViewDelegateFlowLayout {
 
     public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
-        let paddingSpace = sectionInsets.left * (itemsPerRow + 1)
+        let paddingSpace = sectionInsets.left * (itemsPerRow! + 1)
         let availableWidth = view.frame.width - paddingSpace
-        let widthPerItem = availableWidth / itemsPerRow
+        let widthPerItem = availableWidth / itemsPerRow!
 
         return CGSize(width: widthPerItem, height: widthPerItem)
     }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = String.localizedString(for: "MEDIA")
        automaticallyAdjustsScrollViewInsets = false
        setupActivityIndicator()
        PHPhotoLibrary.requestAuthorization { (status) in

class MediaViewController: UIViewController {

    @IBOutlet var collectionView: UICollectionView?
    var itemsPerRow: CGFloat?
    let sectionInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    var dataSource: [PHAsset] = []
    var activityIndicatorView: UIActivityIndicatorView?
