0

In a UICollectionViewCell, is it possible to set a SwiftUI View?

struct MyView: View {
 // ...
}

class MyCollectionViewCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentView.addSubview(MyView())  // How to set this?
    }
}

For the collection view cell, I want to use a Swift UI view. How to set the UICollectionViewCell's content view to MyView?

John Doe
  • 2,225
  • 6
  • 16
  • 44

1 Answers1

0

Found the solution: https://stackoverflow.com/a/56788693/10900045

Using UIHostingController we can add a SwiftUI view to a UIKit view.

John Doe
  • 2,225
  • 6
  • 16
  • 44