Skip to content

Instantly share code, notes, and snippets.

@software-mariodiana
Last active March 22, 2021 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save software-mariodiana/7aa0ac931d78a8b2aa29a381469d3dab to your computer and use it in GitHub Desktop.
Save software-mariodiana/7aa0ac931d78a8b2aa29a381469d3dab to your computer and use it in GitHub Desktop.
Apple documentation lacks milliseconds. This example illustrates use.
#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