问题描述
当读取 NSLocalizedString
的初始值设定项时,我发现某些参数默认为值 default
。 默认
关键字代表什么?
When reading the initializer for a NSLocalizedString
I see that some of the parameters are defaulted to a value default
. What does the default
keyword represent?
func NSLocalizedString(key: String, tableName: String? = default, bundle: NSBundle = default, value: String = default, #comment: String) -> String
推荐答案
这不是一个有效的Swift代码,它是生成的在这里。
This is not a valid Swift code, it's generated on the fly.
默认
这里意味着有一些默认值,但生成器无法将其可视化为你看到它。默认值在技术上是内联函数,因此无法轻松转换为简单声明。
The default
here means that there is some default value but the generator cannot visualize it right for you to see it. The default value is technically an inlined function, therefore it cannot be easily converted to a simple declaration.
您可以看到断言的类似声明
func assert(condition: @auto_closure () -> Bool,
_ message: StaticString = default,
file: StaticString = default,
line: UWord = default)
其中文件
默认为 #file
( __ FILE __
在Swift 1.x)和行
默认为 #line
( __ LINE __
在Swift 1.x中。
Where file
defaults to #file
(__FILE__
in Swift 1.x) and line
defaults to #line
(__LINE__
in Swift 1.x).
在 NSLocalizedString
的情况下,默认值为Localizable
,引用默认本地化文件 Localizable.strings
。
In the case of NSLocalizedString
, the default value is "Localizable"
, referencing the default localization file Localizable.strings
.
这篇关于Swift参数中的默认关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!