<commit_before>//
//  CellReusable.swift
//  Loyalty
//
//  Created by WangKun on 16/1/27.
//  Copyright © 2016年 WangKun. All rights reserved.
//

import Foundation
import UIKit

protocol Reusable:class {
    static var reuseIdentifier: String { get }
    static var nib: UINib? { get }
}

extension UITableViewCell:Reusable {}
extension UICollectionViewCell:Reusable {}

extension Reusable where Self:NSObject {
    static var reuseIdentifier: String {
        let classString : String = NSStringFromClass(self.classForCoder())
        return classString.componentsSeparatedByString(".").last!;
    }
    
    static var nib: UINib? {
        return UINib(nibName: self.reuseIdentifier, bundle: nil)
    }
}

extension UITableView {
    func registerReusableCell<T: UITableViewCell where T: Reusable>(_: T.Type) {
        if let nib = T.nib {
            self.registerNib(nib, forCellReuseIdentifier: T.reuseIdentifier)
        } else {
            self.registerClass(T.self, forCellReuseIdentifier: T.reuseIdentifier)
        }
    }
    
    func dequeueReusableCell<T: UITableViewCell where T: Reusable>() -> T {
        return self.dequeueReusableCellWithIdentifier(T.reuseIdentifier) as! T
    }
    
    func dequeueReusableCell<T: UITableViewCell where T: Reusable>(indexPath indexPath: NSIndexPath) -> T {<commit_msg>简化了这个方法<commit_after>//
//  CellReusable.swift
//  Loyalty
//
//  Created by WangKun on 16/1/27.
//  Copyright © 2016年 WangKun. All rights reserved.
//

import Foundation
import UIKit

protocol Reusable:class {
    static var reuseIdentifier: String { get }
    static var nib: UINib? { get }
}

extension UITableViewCell:Reusable {}
extension UICollectionViewCell:Reusable {}

extension Reusable where Self:NSObject {
    static var reuseIdentifier: String {
        return self.description().componentsSeparatedByString(".").last!;
    }
    
    static var nib: UINib? {
        return UINib(nibName: self.reuseIdentifier, bundle: nil)
    }
}

extension UITableView {
    func registerReusableCell<T: UITableViewCell where T: Reusable>(_: T.Type) {
        if let nib = T.nib {
            self.registerNib(nib, forCellReuseIdentifier: T.reuseIdentifier)
        } else {
            self.registerClass(T.self, forCellReuseIdentifier: T.reuseIdentifier)
        }
    }
    
    func dequeueReusableCell<T: UITableViewCell where T: Reusable>() -> T {
        return self.dequeueReusableCellWithIdentifier(T.reuseIdentifier) as! T
    }
    
    func dequeueReusableCell<T: UITableViewCell where T: Reusable>(indexPath indexPath: NSIndexPath) -> T {
{'fraction_non_alphanumeric': 0.0969743987587277, 'fraction_numerical': 0.0069821567106283944, 'mean_word_length': 3.1663974151857834, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '2118679', 'n_tokens_mistral': 864, 'n_tokens_neox': 790, 'n_words': 192}