NNikN
NNikN

Reputation: 3852

addPeriodicTimeObserver Swift CMTIME

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

The code snippet says , the interval will invoke the block every 0.5 seconds

// Invoke callback every half second

let interval = CMTime(seconds: 0.5,
                          preferredTimescale: CMTimeScale(NSEC_PER_SEC))

If you check the debug logs , and the structure interval holds the following values.

The Value turns out to be 500000000

The timeScale turns out to be 1000000000

Can some one explain how it will give exact 0.5 seconds? As I understand it as 500000000 units each of 1/1000000000

Upvotes: 1

Views: 1086

Answers (1)

jmrueda
jmrueda

Reputation: 1428

Seconds parameter is how often the interval gets triggered (0.5seconds) whilst the preferredTimescale is the resolution of the value, in this case, 10^9. If you debug the function, you will get every 0.5 seconds value in the order 10^-9 seconds (ns).

Upvotes: 1

Related Questions