I'm trying to filter a list of users in a TableViewDiffableDataSource. The filtered array of users is passed to the following function:
private func updateUserCell(_ users: Users? = nil) {
guard let newUsers = users else {
print("No users to show")
return
}
snapShot.deleteItems(viewModel.userList)
dataSource!.apply(snapShot, animatingDifferences: false)
if newUsers == [] { return }
var snapShot = dataSource?.snapshot()
snapShot?.appendItems(newUsers, toSection: .main)
dataSource!.apply(snapShot!, animatingDifferences: true)
}
Debugging shows that the users get appended correctly in the snapshot. But applying shows correct number of filtered users but only the users from the top of the complete list.
i.e. if I have a full list of users [Chloe, Max, John, Martin]. Searching for "jo" only shows Chloe. Searching for "ma" shows Chloe and Max instead of Max and Martin.