Skip to content

Instantly share code, notes, and snippets.

@amannayak0007
Created October 29, 2018 06:00
Show Gist options
  • Save amannayak0007/d00bf801c51bd020587d30ac90eea074 to your computer and use it in GitHub Desktop.
Save amannayak0007/d00bf801c51bd020587d30ac90eea074 to your computer and use it in GitHub Desktop.
Method for dequeueReusableCell
// UITableView.swift
import UIKit
/**
* Extension to provide extra capabilities to existing UITableView.
*/
extension UITableView{
/**
* Method for dequeueReusableCell.
*
* @param T UITableViewCell
* @return T UITableViewCell
*/
func dequeueReusableCell<T:UITableViewCell>(type: T.Type) -> T? {
var fullName: String = NSStringFromClass(T.self)
if let range = fullName.range(of:".", options:.backwards, range:nil, locale: nil){
fullName = fullName.substring(from: range.upperBound)
}
return self.dequeueReusableCell(withIdentifier: fullName) as? T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment