Suprafen / ClimbingHub

App for climbers 🧗🏼‍♀️
1 stars 0 forks source link

DiffableDataSource and array of objects #4

Closed Suprafen closed 2 years ago

Suprafen commented 2 years ago

When I have an array of objects I have only of this for workout after fetching realm. And this is a problem, because only one cell for each section provides. Meanwhile this is absolutely fine for statistics section, it's totally inappropriate for workouts section, because i need to create a number of cells, that is equal to workouts in the realm.

Possible resolving: • When fetching place each object into different array, maybe this will help, but i don't think so

Suprafen commented 2 years ago

The problem was because I used array of arrays in diffable data source, which is not right. You can use your Diffable data source as usual: DataSource<Section, Object>. However, if you want to provide cell which contains collection view with other cells you need to send there array of objects, because configure function receives exactly this collection type.

I figured out that container for desired type would be great. And it is. So you have a container for, which is type of Object. And contains an array of objects. With this approach we satisfy both diffable data sources in main collection view, where we need only one cell and diffable data source where we need an array of objects for inside collection view.

For more info you can check this commit: https://github.com/Suprafen/ClimbingHub/tree/1a659e25dd552931c7513d52bdbb715b5f3b251a