Closed liamnichols closed 3 weeks ago
I think a couple of things to note here:
%
needs to be ignored%%
also needs to be ignoredBut additionally, this has exposed some interesting behaviour with the new foundation APIs...
When using String.init(format:)
, to use a single %
it needs to be escaped as %%
as demonstrated here:
String(format: "50%% off") // 50% off
String(format: "50% off") // 500ff
It seems that String.init(localized:...)
will use String.init(format:)
if there are other arguments in the string, otherwise it won't, so it means that you need to escape the %
only if your string has other arguments. The correct way is like so:
In the future, we could probably add some diagnostics to help flag this, but for now, we probably just want to make sure that we don't mistake %
or %%
as a format specifier.
Given the following:
The current code generates as so:
But this is wrong, it should be: