Xcode’s dispatch_after template
double delayInSeconds = 2.0;
double delayInNanoSeconds = delayInSeconds * NSEC_PER_SEC;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInNanoSeconds);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
});
causes the following warning
Implicit conversion turns floating-point number into integer: ‘double’ to ‘int64_t’ (aka ‘long long’)
because
delayInNanoSeconds is converted from a double to an int64_t implicitly
How bad is this?
Once you’ve converted the time from seconds (expressed in
delayInSeconds) to nanoseconds (expressed indelayInNanoSeconds), you don’t need the extra precision of adoubleand it’s safe to convert to along long. You can cast it in the call todispatch_time():This should cause the warning to go away. Alternatively you could change the type of
delayInNanoSeconds.