Default keyword in Swift parameter

前端 未结 1 1261
再見小時候
再見小時候 2020-11-27 16:55

When reading the initializer for a NSLocalizedString I see that some of the parameters are defaulted to a value default. What does the defaul

相关标签:
1条回答
  • 2020-11-27 17:18

    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.

    You can see similar declarations for 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).

    In the case of NSLocalizedString, the default value is "Localizable", referencing the default localization file Localizable.strings.

    0 讨论(0)
提交回复
热议问题