1
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

NNikN
  • 3,720
  • 6
  • 44
  • 86
  • 500000000/1000000000 is 0.5. Compare http://stackoverflow.com/questions/12902410/trying-to-understand-cmtime. – Martin R Feb 26 '17 at 16:50
  • So , correct me if I am wrong here? CMTimeMakeWithSeconds(0.098, 45)..the value turns out to be 4. so , there are 4 units of 1/45 seconds. – NNikN Feb 26 '17 at 17:28
  • Perhaps this helps: http://stackoverflow.com/questions/42410190/make-cmtime-with-a-very-small-value. – Martin R Feb 26 '17 at 17:31

1 Answers1

1

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).

jmrueda
  • 1,362
  • 19
  • 30