0

So I have a login page that has a video looping in the background and I have done this with the following code:

videoPlayer.play()
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: videoPlayer.currentItem, queue: .main) { [weak self] _ in
            self?.videoPlayer?.seek(to: CMTime.zero)
            self?.videoPlayer?.play()
        }

Question is do I have to remove this observer at deinit or something and if so how do I go about removing the .AVPlayerItemDidPlayToEndTime observer. Not sure of the syntax when it comes to removing these built in observers.

Archid
  • 377
  • 6
  • 21
  • https://developer.apple.com/documentation/foundation/notificationcenter/1413994-removeobserver – matt Dec 02 '19 at 00:16

1 Answers1

1

Swift automatically deinitializes built in observables when the controller is dismissed - just use the following function.

deinit {
    // Release all resources
    // perform the deinitialization
}

there is also a similar question asked here.

Swift deinit

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92