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 provides a default initializer for any structure or class that provides default values for all of its properties and doesn't provide at least one initializer itself. The default initializer simply creates a new instance with all of its properties set to their default values.
Parameters can provide default values to simplify function calls and can be passed as in-out parameters, which modify a passed variable once the function has completed its execution. Every function in Swift has a type, consisting of the function's parameter types and return type.
However there is another data type in Swift called Optional, whose default value is a null value ( nil ). You can use optional when you want a variable or constant contain no value in it. An optional type may contain a value or absent a value (a null value).
Swift inout parameter is a parameter that can be changed inside the function where it's passed into. To accept inout parameters, use the inout keyword in front of an argument. To pass a variable as an inout parameter, use the & operator in front of the parameter.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With