所以我有以下代码:
GameScene:
Rule = Level / 10
let StrRule = String(Rule) //for example Level = 24 -> Rule = 2
let RegelString = String(format: NSLocalizedString("RegelText", comment: ""), StrRule)
//Give the String out in an UILabel as text
RegelLabel.text = RegelString
这就是我的Localizable.strings的样子:
"RegelText" = "You lose %d goals if you miss.";
所以我开始游戏,我的Level
是24.所以Rule
应该是2。
所以我建立并运行但是当我启动应用程序时,他向我展示了一些疯狂的数字。
标签就像:You lose 1314063968 goals if you miss.
为什么它不起作用?
答案 0 :(得分:1)
StrRule
代表数字。 %s
显然不是一个数字。您打算使用RegelText
吗? "RegelText" = "You lose %s goals if you miss.";
应该是这样的:
Rule
或者只使用Rule = Level / 10
let RegelString = String(format: NSLocalizedString("RegelText", comment: ""), Rule)
而不是将其转换为字符串。代码可能是这样的:
RegelText
在这种情况下,%d
仍会使用Level / 10
。
此外,我没有看到您舍入Level / 10
的结果。我知道将整数除以整数会产生整数,而不是小数。但为了安全起见,我认为你应该将round
置于floor
或// app.js
let foo = 3;
let bar = 35;
函数中。