⚠️ Now, it's better to use UIHostingConfiguration. Here is WWDC session that describe how to use it https://developer.apple.com/videos/play/wwdc2022/10072/
- In your Xcode project, navigate to File > Swift Packages > Add Package Dependancy...
- Paste the following into the URL field: https://github.com/cozzin/UIHosting
import UIHosting
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.register(UIHostingCell<ExampleSwiftUIRow>.self, forCellReuseIdentifier: "UIHostingCell")
tableView.delegate = self
tableView.dataSource = self
return tableView
}()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UIHostingCell", for: indexPath) as! UIHostingCell<ExampleSwiftUIRow>
cell.configure(ExampleSwiftUIRow(count: data[indexPath.row]))
return cell
}