In one of the sample codes by Apple, I see the following lines:
int digits = MAX( 0, 2 + floor( log10( newDurationSeconds)));
self.exposureDurationValueLabel.text = [NSString stringWithFormat:@"1/%.*f", digits, 1/newDurationSeconds];
I am not able to understand the syntax, there are two arguments to stringWithFormat: but only one % sign. I understand it is string value of 1/newDurationSeconds upto N=digits but the syntax is something I don't get.
And how do I translate it to Swift 3?
The first parameter supplies the number of decimal digits desired and is represented by the
*, and the second value is the number.In Swift:
Note: This capability is supplied by the Foundation framework. You must
import Foundation(orimport UIKitorimport Cocoa) for it to work.You can find documentation for the format string here (Apple's Documentation) and here (IEEE printf specification).
In the second document, the
*is explained: