Search code examples
syntaxswift

What does # mean in Apple Swift?


I was trying to find what does # symbol means in NSLocalized string declaration in Swift:

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

The only documentation about # I have found is here. And its actually nothing. They just mention that it is registered for punctuation.

So its not like this symbol changes anything but I really would like to know what for is it? It seems that it could work just fine without it...

Any ideas?


Solution

  • Check out the Shorthand External Parameter Names section of this doc: https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-XID_256

    Here is the excerpt in the event the above link does not work in the future:

    Shorthand External Parameter Names

    If you want to provide an external parameter name for a function parameter, and the local parameter name is already an appropriate name to use, you do not need to write the same name twice for that parameter. Instead, write the name once, and prefix the name with a hash symbol (#). This tells Swift to use that name as both the local parameter name and the external parameter name.