我有一个可以向MutableProperty<[Stuff]>
但是当我重新加载collectionView
with 时collectionView.reloadData()
。Web 套接字向 中添加或删除数据MutableProperty<[Stuff]>
,因此会崩溃
由于多种原因,这里有一些错误:
- 当 collectionView 方法使用我的列表时索引超出范围
- 无效的项目数会导致崩溃,例如:
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).'
任何人都有一个好的建议或最佳实践来做到这一点?我已经看到 MutableProperty 是线程安全的
我知道它为什么会崩溃。它崩溃是因为 websockets 在 期间添加或删除数组中的值reloadData
,collectionView
但我不知道如何解决它。我知道我们可以使用信号量,但我正在寻找优雅的东西