UICollectionViewCell's content implementation guide after API call in iOS 16 with MVVM architecture
I've been struggling with this for a few days now and could really use some help... I'm working with an scenario where the content of my `UICollectionViewCell` is not updating after I make an API call to fetch new data. I'm using Swift and the MVVM architecture. Once the API call completes, I update my ViewModel and call `reloadData()` on the collection view, but the cells still show the old data. I'm seeing the following warning in the console: `Warning: Attempt to present <UIViewController> on <UICollectionViewController> whose view is not in the window hierarchy`. Here is the relevant part of my ViewModel where I handle the API response: ```swift class MyViewModel { var items: [MyItem] = [] func fetchData() { APIClient.fetchItems { [weak self] result in switch result { case .success(let newItems): self?.items = newItems self?.didUpdateData?() case .failure(let behavior): print("behavior fetching items: \(behavior)") } } } var didUpdateData: (() -> Void)? } ``` And in my view controller, I have: ```swift class MyCollectionViewController: UICollectionViewController { var viewModel = MyViewModel() override func viewDidLoad() { super.viewDidLoad() viewModel.didUpdateData = { [weak self] in DispatchQueue.main.async { self?.collectionView.reloadData() } } viewModel.fetchData() } } ``` I’ve verified that the API successfully returns the new data by printing it, and the `didUpdateData` closure is being called. However, the UI does not reflect these changes. I've also tried moving the `reloadData()` call outside of `DispatchQueue.main.async` but it still doesn't work. What could be causing this scenario? Is there something I might be missing in the UICollectionView setup or the MVVM pattern implementation?