i want convert these 2 obj-c statements swift. i'm not sure syntax since there multiple object percent signs. have converted of code except print strings percent signs.
i want use swift's native print ("\variable") syntax.
self.validframes.text = [nsstring stringwithformat:@"valid frames: %d%%", min(100, (100 * self.validframecounter)/min_frames_for_filter_to_settle)];
validframes.text = string.localizedstringwithformat("valid frames: \min%%"(100, (100 * validframecounter) / minframesforfiltertosettle))
self.rate.text=[nsstring stringwithformat:@"%0.0f", beat];
rate.text = string.localizedstringwithformat("\beat 0.0f")
please correct swift syntax.
the interpolation syntax
\(expression)
:let validframespercentage = min(100, (100 * self.validframecounter)/min_frames_for_filter_to_settle) self.validframes.text = "valid frames: \(validframespercentage)%"
you don't have control on how swift formats float if use interpolation syntax. example:
let beat = float(10.0/3) self.rate.text = "\(beat)" // text 3.33333; can't specify number of digits
if want use localized strings, can't use
\(...)
interpolation. perform interpolation, compiler has examine string. localized strings loaded data file @ runtime. compiler doesn't @ them.using format strings in swift 100% ok. part of library,
uiview
(ornsview
).