Created
February 23, 2021 19:16
-
-
Save karigrooms/3e9664e6d997b02162b923e5f4778933 to your computer and use it in GitHub Desktop.
Blog post: SwiftUI with UICollectionView - 5. Add SwiftUI UIHostingController as a child of our UIViewController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
extension CollectionViewExample: UICollectionViewDataSource { | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return 9 | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MyCollectionViewCell.reuseIdentifier, for: indexPath) as? MyCollectionViewCell else { | |
fatalError("Could not dequeue cell") | |
} | |
// Add SwiftUI UIHostingController as a child of our UIViewController | |
cell.embed(in: self) | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment