<commit_before>//
//  Copyright © 2016 <NAME>. All rights reserved.

import UIKit
 
final class HomeCollectionViewController: UICollectionViewController {
  required init?(coder aDecoder: NSCoder) {
    self.dataSource = CollectionDataSource(
      collection: self.collection,
      configureCell: self.dynamicType.configureCell,
      cellIdentifier: Storyboards.Cell.HomeCollection
    )

    super.init(coder: aDecoder)
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    self.collectionView?.dataSource = self.dataSource
  }

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    super.prepareForSegue(segue, sender: sender)

    if let destinationViewController = segue.destinationTopViewController as? SettableHomeItem {
      guard let indexPath = sender as? NSIndexPath else {
        fatalError("`SettableHomeItem` requires `indexPath` to be sent as the sender.")
      }

      destinationViewController.item = self.collection[indexPath]
    }
  }

  //MARK: - Private
  private var collection = CollectableCollection<HomeItem>(items: .HomeCollection)
  private var dataSource: CollectionDataSource<HomeItem, HomeCollectionCell>
}
 
private extension HomeCollectionViewController {
  static func configureCell(cell: HomeCollectionCell, withItem item: HomeItem) {
    cell.titleLabel.text = item.title
    
    // TODO: remove **the check** later on. This is just for testing purposes while we don't have images ready.
    if let iconImage = UIImage(named: item.iconName) {
      cell.imageView.image = iconImage
    } else {
      cell.imageView.image = UIImage(named: "icon_AlertView")
    }
  }
}

// MARK:- UICollectionViewDelegate
extension HomeCollectionViewController {
  override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let item = self.collection[indexPath]

    self.performSegueWithIdentifier(item.segueIdentifier, sender: indexPath)
  }
}<commit_msg>Improves code organization<commit_after>//
//  Copyright © 2016 <NAME>. All rights reserved.

import UIKit
 
final class HomeCollectionViewController: UICollectionViewController {
  required init?(coder aDecoder: NSCoder) {
    self.dataSource = CollectionDataSource(
      collection: self.collection,
      configureCell: self.dynamicType.configureCell,
      cellIdentifier: Storyboards.Cell.HomeCollection
    )

    super.init(coder: aDecoder)
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    self.collectionView?.dataSource = self.dataSource
  }

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    super.prepareForSegue(segue, sender: sender)

    if let destinationViewController = segue.destinationTopViewController as? SettableHomeItem {
      guard let indexPath = sender as? NSIndexPath else {
        fatalError("`SettableHomeItem` requires `indexPath` to be sent as the sender.")
      }

      destinationViewController.item = self.collection[indexPath]
    }
  }

  // MARK: - Private
  private var collection = CollectableCollection<HomeItem>(items: .HomeCollection)
  private var dataSource: CollectionDataSource<HomeItem, HomeCollectionCell>
}
 
private extension HomeCollectionViewController {
  static func configureCell(cell: HomeCollectionCell, withItem item: HomeItem) {
    cell.titleLabel.text = item.title
    
    // TODO: remove **the check** later on. This is just for testing purposes while we don't have images ready.
    if let iconImage = UIImage(named: item.iconName) {
      cell.imageView.image = iconImage
    } else {
      cell.imageView.image = UIImage(named: "icon_AlertView")
    }
  }
}

// MARK:- UICollectionViewDelegate
extension HomeCollectionViewController {
  override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let item = self.collection[indexPath]

    self.performSegueWithIdentifier(item.segueIdentifier, sender: indexPath)
  }
}
{'fraction_non_alphanumeric': 0.08437970868910095, 'fraction_numerical': 0.0020090406830738324, 'mean_word_length': 4.186197916666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6430680', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1071, 'n_words': 276}