Swift中的NSLocalizedString等效项是什么?

拉法尔

有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

tableNamebundlevalue参数均标有default该装置的同时调用该函数我们可以忽略这些参数的关键字。在这种情况下,将使用其默认值。

这得出一个结论,该方法调用可以简化为:

NSLocalizedString("key", comment: "comment")

Swift 5-不变,仍然可以正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章