I have a web socket that can add or remove data to a MutableProperty<[Stuff]>
But when I reload the collectionView
with collectionView.reloadData()
.
Web sockets add or remove data to the MutableProperty<[Stuff]>
, so it will crash
for multiple causes here is some errors:
- Index out of range when collectionView methods use my list
- Invalid number of items cause crash like:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (58) must be equal to the number of sections contained in the collection view before the update (59), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
Anyone has a good advice or best practice to do that ? I've see that MutableProperty is thread safe
I know why it crash. It crash because websockets add or remove values from the array during the reloadData
of the collectionView
but I do not know how to solve it.
I know we can use semaphore but I'm looking for something elegant