I have 2 UICollectionView controllers (a Storefront where customers can see all the products and Backend where I can CRUD items) that are embedded into a TabBarViewController. Both view controllers have separate data sources (initially they include identical items, in my case objects with "name" and "price" properties) that populate them.
The idea is pretty simple: let's say, I click on a cell in Backend VC, Detail VC is presented modally, I edit some properties of the object and confirm changes. What I want is that the changes to the object be visible both to Backend VC and Storefront VC.
The first thing that come to my mind is to implement NotificationCenter to broadcast changes from Detail VC to both Backend and Storefront but here's the thing: everything's okay when I receive the item in Backend VC and call snapshot.reloadItems since the item belonged to Backend VC datasource, but when Storefront VC receives the same item I get the following error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: indexPath || ignoreInvalidItems'.
I understand that diffable data sources are based on the idea of items being identical or not so when I pass an item from Backend's data source to Storefront's data source, Storefront's data source doesn't know how to implement snapshot.reloadItems since it didn't have the item with the appropriate id in the first place.
Any ideas how to implement the above-mentioned using diffable data sources and NotificationCenter? Or any other methods?
I thought about having the shared data source for both Storefront and Backend but not sure if that's a reasonable thing to do and if it'll bring trouble in the future.
The only solution I found was to change my model from Struct to Class. This way everything works perfectly fine.