Instance Method


Cancels a previously registered periodic or boundary time observer.


func removeTimeObserver(_ observer: Any)




Upon return, the caller is guaranteed that no new time observer blocks will begin executing. Depending on the calling thread and the queue used to add the time observer, an in-flight block may continue to execute after this method returns. You can guarantee synchronous time observer removal by enqueuing the call to removeTimeObserver on that queue. Alternatively, call dispatch_sync(queue, ^{}) after removeTimeObserver to wait for any in-flight blocks to finish executing.

You should use this method to explicitly cancel each time observer added using addPeriodicTimeObserver(forInterval:queue:using:) and addBoundaryTimeObserver(forTimes:queue:using:).

The following shows a common implementation to remove a registered time observer:

func removePeriodicTimeObserver() {
    // If a time observer exists, remove it
    if let token = timeObserverToken {
        timeObserverToken = nil

See Also

Observing Time

func addPeriodicTimeObserver(forInterval: CMTime, queue: DispatchQueue?, using: (CMTime) -> Void) -> Any

Requests the periodic invocation of a given block during playback to report changing time.

func addBoundaryTimeObserver(forTimes: [NSValue], queue: DispatchQueue?, using: () -> Void) -> Any

Requests the invocation of a block when specified times are traversed during normal playback.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software