Avatar
@hiragram import UIKit protocol ProtocolA { init?(coder: NSCoder) static var name: String { get } } class CustomCell: UITableViewCell, ProtocolA { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } static var name: String { return "CustomCell" } } class ProtocolACellFactory { init<X: UITableViewCell & ProtocolA>(_ type: X.Type) { _build = { X.init() } _name = { type.name } } func build() -> UITableViewCell & ProtocolA { return _build() } var _build: () -> UITableViewCell & ProtocolA var _name: () -> String } func hoge(cellFactory: ProtocolACellFactory) {} let cells = [ProtocolACellFactory.init(CustomCell.self), ProtocolACellFactory.init(CustomCell.self), ProtocolACellFactory.init(CustomCell.self)] cells.forEach { hoge(cellFactory: $0) }