[ad_1]
So I’m calling this right into a colleciton view. This instance is for SwiftUI however I’m creationg a group view with an inventory format.
Instance: https://hygraph.com/weblog/swift-with-hygraph
I’ve accomplished all the opposite setup which you’ll find within the gist however I hold getting these errors:
[Common] Snapshot request 0x60000348db30 full with error: <NSError: 0x600003489020; area: FBSSceneSnapshotErrorDomain; code: 4; purpose: "an unrelated situation or state was not happy">
My Gist: https://github.com/ImranRazak1/HygraphSwift
View Controller
import UIKit
class ViewController: UIViewController {
enum Part {
case most important
}
var collectionView: UICollectionView!
var dataSource: UICollectionViewDiffableDataSource<Part,Product>?
var merchandise: [Product] = []
override func viewDidLoad() {
tremendous.viewDidLoad()
// Do any extra setup after loading the view.
navigationItem.title = "Merchandise"
view.backgroundColor = .white
//Uncomment when wanted
configureHierarchy()
configureDataSource()
collectionView.register(ListCell.self, forCellWithReuseIdentifier: "ListCell")
}
func loadProducts() async {
self.merchandise = await APIService().listProducts()
}
func configure<T: SelfConfiguringCell>(with product: Product, for indexPath: IndexPath) -> T {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ListCell", for: indexPath) as? T else {
fatalError("Unable to dequeue Cell")
}
cell.configure(with: product)
return cell
}
}
extension ViewController {
personal func createLayout() -> UICollectionViewLayout {
let config = UICollectionLayoutListConfiguration(look: .insetGrouped)
return UICollectionViewCompositionalLayout.record(utilizing: config)
}
}
extension ViewController {
personal func configureHierarchy() {
collectionView = UICollectionView(body: view.bounds, collectionViewLayout: createLayout())
collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(collectionView)
collectionView.delegate = self
}
personal func configureDataSource() {
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Product> { (cell, indexPath, product) in
var content material = cell.defaultContentConfiguration()
content material.textual content = "(product.title)"
cell.contentConfiguration = content material
}
dataSource = UICollectionViewDiffableDataSource<Part, Product>(collectionView: collectionView) {
(collectionView: UICollectionView, indexPath: IndexPath, identifier: Product) -> UICollectionViewCell? in
return collectionView.dequeueConfiguredReusableCell(utilizing: cellRegistration, for: indexPath, merchandise: identifier)
}
//inital information
var snapshot = NSDiffableDataSourceSnapshot<Part, Product>()
snapshot.appendSections([.main])
//Downside loading this info
snapshot.appendItems(merchandise, toSection: .most important)
dataSource?.apply(snapshot, animatingDifferences: false)
Activity {
do {
await self.loadProducts()
snapshot.appendItems(merchandise, toSection: .most important)
await dataSource?.apply(snapshot, animatingDifferences: false)
}
}
}
}
extension ViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)
}
}
Finest,
Imran
[ad_2]
