Reputation: 81
I am trying to remove two view controllers from a tab bar controller, it's crashing the application.
Removing one controller is easily done
let index = 0 //0 to 5
viewControllers?.remove(at: index)
But when i try to remove more than one, application crash. Can anyone help me.
Upvotes: 1
Views: 679
Reputation: 914
If you are removing them from index 0...5, then the indices will no longer correct after removing the first item and you would eventually get an index out of range exception. Something you could do would be to remove them starting with the greatest index and going down to zero (5...0).
As pointed out below, if all you want to do is removed the first five, you could simply call viewControllers?.removeFirst(5)
.
Upvotes: 1