Created
November 12, 2020 14:37
-
-
Save tooszovski/2ed8151f6b6b9df36268a4d72d392fac to your computer and use it in GitHub Desktop.
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
import UIKit | |
public final class GenericTableCell<View: UIView>: UITableViewCell { | |
let view = View() | |
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
contentView.addSubview(view) | |
makeConstraints() | |
} | |
@available(*, unavailable) | |
required init?(coder _: NSCoder) { | |
preconditionFailure("init(coder:) has not been implemented") | |
} | |
} | |
private extension GenericTableCell { | |
func makeConstraints() { | |
let views = ["contentView": contentView, | |
"genericView": view] | |
let constraints = [ | |
NSLayoutConstraint.constraints(withVisualFormat: "V:|genericView|", | |
metrics: nil, | |
views: views), | |
NSLayoutConstraint.constraints(withVisualFormat: "H:|genericView|", | |
metrics: nil, | |
views: views) | |
] | |
.flatMap { $0 } | |
NSLayoutConstraint.activate(constraints) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment