Friday, November 25, 2022
HomeiOS Developmentios - The right way to name Async Job inside view did...

ios – The right way to name Async Job inside view did load for Assortment View?

So I’m calling this right into a colleciton view. This instance is for SwiftUI however I’m creationg a set view with a listing structure.


I’ve achieved all the opposite setup which you will discover within the gist however I maintain getting these errors:

[Common] Snapshot request 0x60000348db30 full with error: <NSError: 0x600003489020; area: FBSSceneSnapshotErrorDomain; code: 4; motive: "an unrelated situation or state was not happy">

My Gist:

View Controller

import UIKit

class ViewController: UIViewController {

    enum Part {
        case important

    var collectionView: UICollectionView!
    var dataSource: UICollectionViewDiffableDataSource<Part,Product>?
    var merchandise: [Product]  = []

    override func viewDidLoad() {
        // Do any further setup after loading the view.

        navigationItem.title = "Merchandise"
        view.backgroundColor = .white

        //Uncomment when wanted
        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 {
    non-public func createLayout() -> UICollectionViewLayout {
        let config = UICollectionLayoutListConfiguration(look: .insetGrouped)
        return UICollectionViewCompositionalLayout.record(utilizing: config)

extension ViewController {
    non-public func configureHierarchy() {
        collectionView = UICollectionView(body: view.bounds, collectionViewLayout: createLayout())
        collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        collectionView.delegate = self

    non-public 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 knowledge

        var snapshot = NSDiffableDataSourceSnapshot<Part, Product>()
        //Downside loading this data
        snapshot.appendItems(merchandise, toSection: .important)
        dataSource?.apply(snapshot, animatingDifferences: false)

        Job {
            do {
                await self.loadProducts()
               snapshot.appendItems(merchandise, toSection: .important)
                await dataSource?.apply(snapshot, animatingDifferences: false)



extension ViewController: UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        collectionView.deselectItem(at: indexPath, animated: true)




Please enter your comment!
Please enter your name here

Most Popular

Recent Comments