Skip to content

Instantly share code, notes, and snippets.

@fmo91
Created October 4, 2016 03:57
Show Gist options
  • Save fmo91/70805bc21133a2057c366894d8e40a6f to your computer and use it in GitHub Desktop.
Save fmo91/70805bc21133a2057c366894d8e40a6f to your computer and use it in GitHub Desktop.
Simple protocol extension for easily registering UITableViewCell without hardcoding strings.
//
// Registrable.swift
//
// Created by Fernando Ortiz on 9/30/16.
// Copyright © 2016 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
/**
Protocol extension used to easily regiter UITableViewCells in UITableView
without using Strings (because they are too error-prone).
As an example:
ATableViewCell.register(in: self.tableView)
This protocol does not require the UITableViewCell subclass implements any method.
*/
protocol Registrable {}
extension Registrable where Self:UITableViewCell {
static func register(in tableView: UITableView) {
tableView.register(UINib(nibName: String(describing: Self.self), bundle: nil), forCellReuseIdentifier: String(describing: Self.self))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment