I am trying to remove an item from a public static array that is been shown in a tableview. The deletion is occuring in a different viewcontroller and when I try to enter that view controller the app crashes with the error of 'Index out of range'
this is where i delete the Item
func removeItem (info:Dictionary<String, Any>){
let stringKey = info[KEYS.stringKey] as! String
for var i in 0 ..< ItemsViewController.itemVideosList.count {
let current = ItemsViewController.itemVideosList[i]
let currentStringKey = current[KEYS.stringKey] as! String
if stringKey == currentStringKey {
ItemsViewController.itemVideosList.remove(at: i)
return
}
}
I call this method on a button click here:
@IBAction func FavoriteAction(_ sender: Any) {
if Flag {
removeFromFavorite(info: songInfo)
Flag = false
}
else {
ItemsViewController.itemVideosList.insert(songInfo, at: 0)
favFlag = true
}
}
I am populating the table view in 'ItemsViewController' viewDidLoad with this method
func loadItems() {
DispatchQueue.main.async {
self.itemsTableView.reloadData()
}
}
thanks