且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift 中的 NSLocalizedString 等价物是什么?

更新时间:2022-06-08 18:23:04

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

tableNamebundlevalue 参数标有 default 关键字,这意味着我们可以在调用函数时省略这些参数.在这种情况下,将使用它们的默认值.

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 5 - 没有变化,仍然如此.

Swift 5 - no change, still works like that.