<commit_before>//
//  Created by <NAME>
//  http://www.jessesquires.com
//
//
//  Documentation
//  http://cocoadocs.org/docsets/JSQDataSourcesKit
//
//
//  GitHub
//  https://github.com/jessesquires/JSQDataSourcesKit
//
//
//  License
//  Copyright (c) 2015 <NAME>
//  Released under an MIT license: http://opensource.org/licenses/MIT
//

import Foundation
import UIKit
import CoreData


public class TableViewFetchedResultsDelegate <Cell: UITableViewCell, DataItem>: NSFetchedResultsControllerDelegate {

    public weak var tableView: UITableView?

    public let cellFactory: TableViewCellFactory<Cell, DataItem>

    public init(tableView: UITableView, cellFactory: TableViewCellFactory<Cell, DataItem>) {
        self.tableView = tableView
        self.cellFactory = cellFactory
    }

    // MARK: fetched results controller delegate

    public func controllerWillChangeContent(controller: NSFetchedResultsController) {
        tableView?.beginUpdates()
    }

    public func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
        switch type {
        case .Insert:
            tableView?.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
        case .Delete:
            tableView?.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
        default:
            break
        }
    }

    public func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
        switch type {
        case .Insert:
            if let i = indexPath {
                tableView?.insertRowsAtIndexPaths([i], withRowAnimation: .Fade)
            }
        case .Delete:
            if let i = indexPath {
                tableView?.deleteRowsAtIndexPaths([i], withRowAnimation: .Fade)
            }
        case .Update:
            if let i = indexPath, cell = tableView?.cellForRowAtIndexPath(i) {
                cellFactory.configureCell(cell as! Cell, forItem: anObject as! DataItem, inTableView: tableView!, atIndexPath: indexPath!)
            }
        case .Move:
            if let deleteIndexPath = indexPath {
                tableView?.deleteRowsAtIndexPaths([deleteIndexPath], withRowAnimation: .Fade)
            }

            if let insertIndexPath = newIndexPath {
                tableView?.insertRowsAtIndexPaths([insertIndexPath], withRowAnimation: .Fade)
            }
        }
    }

    public func controllerDidChangeContent(controller: NSFetchedResultsController) {
        tableView?.endUpdates()
    }
    
}
<commit_msg>use generic TableViewCellFactoryType in TableViewFetchedResultsDelegate, not concrete TableViewCellFactory. derp.<commit_after>//
//  Created by <NAME>
//  http://www.jessesquires.com
//
//
//  Documentation
//  http://cocoadocs.org/docsets/JSQDataSourcesKit
//
//
//  GitHub
//  https://github.com/jessesquires/JSQDataSourcesKit
//
//
//  License
//  Copyright (c) 2015 <NAME>
//  Released under an MIT license: http://opensource.org/licenses/MIT
//

import Foundation
import UIKit
import CoreData


public class TableViewFetchedResultsDelegate <DataItem, CellFactory: TableViewCellFactoryType
                                                where
                                                CellFactory.DataItem == DataItem>: NSFetchedResultsControllerDelegate {

    public weak var tableView: UITableView?

    public let cellFactory: CellFactory

    public init(tableView: UITableView, cellFactory: CellFactory) {
        self.tableView = tableView
        self.cellFactory = cellFactory
    }

    // MARK: fetched results controller delegate

    public func controllerWillChangeContent(controller: NSFetchedResultsController) {
        tableView?.beginUpdates()
    }

    public func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {
        switch type {
        case .Insert:
            tableView?.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
        case .Delete:
            tableView?.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade)
        default:
            break
        }
    }

    public func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
        switch type {
        case .Insert:
            if let i = indexPath {
                tableView?.insertRowsAtIndexPaths([i], withRowAnimation: .Fade)
            }
        case .Delete:
            if let i = indexPath {
                tableView?.deleteRowsAtIndexPaths([i], withRowAnimation: .Fade)
            }
        case .Update:
            if let i = indexPath, cell = tableView?.cellForRowAtIndexPath(i) {
                cellFactory.configureCell(cell as! CellFactory.Cell, forItem: anObject as! DataItem, inTableView: tableView!, atIndexPath: indexPath!)
            }
        case .Move:
            if let deleteIndexPath = indexPath {
                tableView?.deleteRowsAtIndexPaths([deleteIndexPath], withRowAnimation: .Fade)
            }

            if let insertIndexPath = newIndexPath {
                tableView?.insertRowsAtIndexPaths([insertIndexPath], withRowAnimation: .Fade)
            }
        }
    }

    public func controllerDidChangeContent(controller: NSFetchedResultsController) {
        tableView?.endUpdates()
    }
    
}

{'fraction_non_alphanumeric': 0.08620988725065047, 'fraction_numerical': 0.0013876843018213356, 'mean_word_length': 2.6656071201525746, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5108822', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1490, 'n_words': 343}