简体   繁体   English

Swift参数中的默认关键字

[英]Default keyword in Swift parameter

When reading the initializer for a NSLocalizedString I see that some of the parameters are defaulted to a value default . 在读取NSLocalizedString的初始化程序时,我看到一些参数默认为default What does the default keyword represent? default关键字代表什么?

func NSLocalizedString(key: String, tableName: String? = default, bundle: NSBundle = default, value: String = default, #comment: String) -> String

This is not a valid Swift code, it's generated on the fly. 这不是有效的Swift代码,它是即时生成的。

The default here means that there is some default value but the generator cannot visualize it right for you to see it. default在这里意味着有一些默认值,但发电机不能想像它适合你才能看到它。 The default value is technically an inlined function, therefore it cannot be easily converted to a simple declaration. 从技术上来说,默认值是一个内联函数,因此不能轻易将其转换为简单的声明。

You can see similar declarations for assert 您可以看到类似的assert

func assert(condition: @auto_closure () -> Bool,
            _ message: StaticString = default,
                 file: StaticString = default,
                 line: UWord = default)

Where file defaults to #file ( __FILE__ in Swift 1.x) and line defaults to #line ( __LINE__ in Swift 1.x). 其中file默认为#file (在Swift 1.x中为#file __FILE__ ), line默认为#line (在Swift 1.x中为__LINE__ )。

In the case of NSLocalizedString , the default value is "Localizable" , referencing the default localization file Localizable.strings . 对于NSLocalizedString ,默认值为"Localizable" ,引用默认的本地化文件Localizable.strings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM