Created
October 4, 2016 03:57
-
-
Save fmo91/70805bc21133a2057c366894d8e40a6f to your computer and use it in GitHub Desktop.
Simple protocol extension for easily registering UITableViewCell without hardcoding strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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