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?

johndoe
  • 1,721
  • 3
  • 13
  • 33

1 Answers1

0

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

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

johndoe
  • 1,721
  • 3
  • 13
  • 33