有Swift的等效项NSLocalizedString(...)
吗?在中Objective-C
,我们通常使用:
NSString *string = NSLocalizedString(@"key", @"comment");
如何在Swift中实现相同目标?我发现了一个功能:
func NSLocalizedString(
key: String,
tableName: String? = default,
bundle: NSBundle = default,
value: String = default,
#comment: String) -> String
但是,它很长,根本不方便。
将NSLocalizedString
在斯威夫特的世界同样存在。
func NSLocalizedString(
key: String,
tableName: String? = default,
bundle: NSBundle = default,
value: String = default,
#comment: String) -> String
的tableName
,bundle
和value
参数均标有default
该装置的同时调用该函数我们可以忽略这些参数的关键字。在这种情况下,将使用其默认值。
这得出一个结论,该方法调用可以简化为:
NSLocalizedString("key", comment: "comment")
Swift 5-不变,仍然可以正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句