I had created extension :
public extension UITableViewCell {
/// Generated cell identifier derived from class name
static func cellIdentifier() -> String {
return String(describing: self)
}
var indexPath:IndexPath?{
return tableView?.indexPath(for: self)
}
var tableView: UITableView? {
var view = superview
while let v = view, v.isKind(of: UITableView.self) == false {
view = v.superview
}
return view as? UITableView
}
}
I am trying to use extension in uitableviewcell class :
func setup(viewModel: ViewModelClass) {
if indexPath != nil {
print("indexpath")
}else {
print("nil") // But it always gives nill.
}
}
I want to fetch section and row for index in uitableviewcell.