I have a video player in my app. There is a list of videos in a collection view. If you tap on one of the cells, a new view controller appears to play the selected video. Al
Here is the workaround solution. Check if it works.
class PlayerViewControllerr: UIViewController { var arrayForIndex = [Int]() var videos = List() @IBAction func didToggleStarButton(_ sender: UIButton) { self.arrayForIndex.append(currentIndexInVideosList) } @overide func viewWillDisappear(_ animated : Bool){ super.viewWillDisappear(animated) for i in arrayForIndex{ let realm = try! Realm() try! realm.write { let videoToDelete = videos[i] /// Get the video that is currently playing realm.delete(videoToDelete) } } }