Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cozzin/uihosting

🖼 Using SwiftUI in UITableViewCell
https://github.com/cozzin/uihosting

Last synced: 11 days ago
JSON representation

🖼 Using SwiftUI in UITableViewCell

Awesome Lists containing this project

README

        

# UIHosting

⚠️ Now, it's better to use [UIHostingConfiguration](https://developer.apple.com/documentation/SwiftUI/UIHostingConfiguration). Here is WWDC session that describe how to use it https://developer.apple.com/videos/play/wwdc2022/10072/

## 🚀 Motivation
- Using SwiftUI in UITableViewCell
- [UITableViewCell에서 SwiftUI 사용하기 - SwiftUI와 UIKit을 함께 사용하며 겪은 시행착오](https://medium.com/@hongseongho/uitableviewcell%EC%97%90%EC%84%9C-swiftui-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-43321a9e9e90)

## 🧰 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
```swift
import UIHosting

private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.register(UIHostingCell.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
cell.configure(ExampleSwiftUIRow(count: data[indexPath.row]))
return cell
}
```