Last active
March 22, 2021 18:07
-
-
Save software-mariodiana/7aa0ac931d78a8b2aa29a381469d3dab to your computer and use it in GitHub Desktop.
Apple documentation lacks milliseconds. This example illustrates use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) | |
{ | |
@autoreleasepool { | |
// Arg 2 is nanoseconds. | |
// | |
// https://developer.apple.com/documentation/dispatch/1420519-dispatch_time | |
dispatch_time_t now = dispatch_time(DISPATCH_TIME_NOW, 0); | |
// Add 1 second for reference. | |
dispatch_time_t second = dispatch_time(now, 1 * NSEC_PER_SEC); | |
// NSEC_PER_MSEC has, "No overview available," because Apple sucks. So, I | |
// assume it means milliseconds. If I times it by 100, I get tenths of a | |
// second. | |
// | |
// https://developer.apple.com/documentation/dispatch/nsec_per_msec?language=objc | |
dispatch_time_t tenth = dispatch_time(now, 1 * NSEC_PER_MSEC * 100); | |
// Then I compare the three. | |
NSLog(@"%llu", now); | |
NSLog(@"%llu", tenth); | |
NSLog(@"%llu", second); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment