<commit_before>//
//  OptionSixViewController.swift
//  DynamicWidthCollectionViewCells
//
//  Created by <NAME> on 2/28/16.
//  Copyright © 2016 matrixprojects.net. All rights reserved.
//

import UIKit

class OptionSixViewController: UIViewController {
  @IBOutlet var collectionView: UICollectionView!
  
  struct Item {
    let name : String
  }
  
  var items = [Item]()
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    collectionView.registerNib(CollectionViewCell.nib, forCellWithReuseIdentifier: "cell")
    
    updateItems()
    collectionView.reloadData()
  }
  
  // MARK: Private
  
  private func updateItems() {
    items.removeAll()
    for i in 0...25 {
      items.append(Item(name: "Cell \(i)"))
    }
  }
  
  override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    collectionView.collectionViewLayout.invalidateLayout()
  }
}

extension OptionSixViewController: UICollectionViewDataSource {
  func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return items.count
  }
  
  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
    cell.textLabel.text = items[indexPath.item].name
    return cell
  }
}

extension OptionSixViewController: UICollectionViewDelegateFlowLayout {
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    return CGSizeMake(collectionView.frame.width, CGFloat(68))
  }
}<commit_msg>Option 6 - added sectionInset to item size calculations<commit_after>//
//  OptionSixViewController.swift
//  DynamicWidthCollectionViewCells
//
//  Created by <NAME> on 2/28/16.
//  Copyright © 2016 matrixprojects.net. All rights reserved.
//

import UIKit

class OptionSixViewController: UIViewController {
  @IBOutlet var collectionView: UICollectionView!
  
  struct Item {
    let name : String
  }
  
  var items = [Item]()
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    collectionView.registerNib(CollectionViewCell.nib, forCellWithReuseIdentifier: "cell")
    
    updateItems()
    collectionView.reloadData()
  }
  
  // MARK: Private
  
  private func updateItems() {
    items.removeAll()
    for i in 0...25 {
      items.append(Item(name: "Cell \(i)"))
    }
  }
  
  override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    collectionView.collectionViewLayout.invalidateLayout()
  }
}

extension OptionSixViewController: UICollectionViewDataSource {
  func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return items.count
  }
  
  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
    cell.textLabel.text = items[indexPath.item].name
    return cell
  }
}

extension OptionSixViewController: UICollectionViewDelegateFlowLayout {
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout, insets = flowLayout.sectionInset
    let itemWidth = collectionView.frame.width - insets.left - insets.right, itemHeight = CGFloat(68)
    
    return CGSizeMake(itemWidth, itemHeight)
  }
}
{'fraction_non_alphanumeric': 0.08809267241379311, 'fraction_numerical': 0.0078125, 'mean_word_length': 4.304285714285714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5525682', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1080, 'n_words': 231}