public final class ViewHostingCollectionViewCell: UICollectionViewCell, ConfigurableCell where Item == View.Item { // MARK: Properties /// The reuse identifier, made unique by using the type of the wrapped view. public static var reuseIdentifier: String { return "hosted-\(String(describing: View.self))"} /// The hosted view. public let hostedView: View /// The selection state of the cell. public override var isSelected: Bool { didSet { hostedView.isSelected = isSelected } } /// The highlight state of the cell. public override var isHighlighted: Bool { didSet { hostedView.isHighlighted = isHighlighted } } // MARK: Initialization public override init(frame: CGRect) { hostedView = View(frame: frame) super.init(frame: frame) contentView.addSubview(hostedView) hostedView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ hostedView.widthAnchor.constraint(equalTo: contentView.widthAnchor), hostedView.centerXAnchor.constraint(equalTo: contentView.centerXAnchor), hostedView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor), contentView.topAnchor.constraint(equalTo: hostedView.topAnchor), contentView.bottomAnchor.constraint(equalTo: hostedView.bottomAnchor) ]) } public required init?(coder: NSCoder) { fatalError() } // MARK: Cell Configuration public override func prepareForReuse() { super.prepareForReuse() hostedView.prepareForReuse() } @discardableResult public func configure(for item: Item) -> Self { hostedView.configure(for: item) return self } }