问题描述
是否有Swift等价的 NSLocalizedString(...)
?
在 Objective-C
中,我们通常使用:
Is there an Swift equivalent of NSLocalizedString(...)
?In Objective-C
, we usually use:
NSString *string = NSLocalizedString(@"key", @"comment");
如何在Swift中实现相同的目标?我发现了一个函数:
How can I achieve the same in Swift? I found a function:
func NSLocalizedString(
key: String,
tableName: String? = default,
bundle: NSBundle = default,
value: String = default,
#comment: String) -> String
然而,它很长且根本不方便。
However, it is very long and not convenient at all.
推荐答案
NSLocalizedString
也存在于Swift的世界中。
The NSLocalizedString
exists also in the Swift's world.
func NSLocalizedString(
key: String,
tableName: String? = default,
bundle: NSBundle = default,
value: String = default,
#comment: String) -> String
tableName
,捆绑
,值
参数标有 默认
关键字表示我们可以在调用函数时省略这些参数。在这种情况下,将使用它们的默认值。
The tableName
, bundle
, and value
parameters are marked with a default
keyword which means we can omit these parameters while calling the function. In this case, their default values will be used.
这导致结论是方法调用可以简化为:
This leads to a conclusion that the method call can be simplified to:
NSLocalizedString("key", comment: "comment")
这篇关于什么是Swift中的NSLocalizedString等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!