Skip to content

cozzin/UIHosting

Repository files navigation

UIHosting

⚠️ 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/

🚀 Motivation

🧰 Setup

  1. In your Xcode project, navigate to File > Swift Packages > Add Package Dependancy...
  2. Paste the following into the URL field: https://github.com/cozzin/UIHosting

🧑‍💻 Usage

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
}