What would be the best solution in Swift for a precise clock to control external hardware? I need to write a loop function that would fire at a set rate per second (hundreds or thousands Hz) reliably and with high precision.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
You can define a GCD timer property (because unlike
NSTimer
/Timer
, you have to maintain your own strong reference to the GCD timer):And then make a timer (probably a
.strict
one that is not subject to coalescing, app nap, etc., with awareness of the power/battery/etc. implications that entails) withmakeTimerSource(flags:queue:)
:Note, you should gracefully handle situations where the timer cannot handle the precision you are looking for. As the documentation says: