Reputation: 375
Is there a way in Swift to remove rows from TableView when a maximum number of rows is reached?
My TableView is populated by an array of random images via asynchronous downloads. As the user scrolls down the TableView, more random images get downloaded and the TableView is populated.
It's pretty much an endless list.
Over time, the array and the TableView will become quite large and I want to do some house keeping to remove the oldest rows in the TableView and the oldest items in the array, (i.e. index 0).
Is there a way to safely remove them. Everything I have tried crashes the app.
Upvotes: 1
Views: 1045
Reputation: 112875
When adding a new entry to the data model array and that would exceed your desired count, delete the oldest. If the array is not sorted by date sort it into a new array and pick the oldest for deletion from the data model array.
Upvotes: 2