Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 1.35 KB

README.md

File metadata and controls

30 lines (24 loc) · 1.35 KB

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
}