Search code examples
iosswiftxcodeparametersfunc

Xcode func shows gray instead of white params


Hello i am working with Xcode and i have noticed that some function are behaving different then usual, for example :

function showing parameters in gray

  let config = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [UIMenuElement] in
        let downloadAction = UIAction(title: "Download",subtitle: nil, state: .off) { _ in
            print("download")
        }

why does Xcode show the functions in gray and not regular white?

why when i select the function, Xcode writes the function without the parameters and I have to write them out manually?


Solution

  • That is because the parameters of those overloads are all optional. Optional parameters are all shown in grey* in the autocomplete box in Xcode 14.

    If the function has some required parameters, and some optional parameters, you can see that the required ones are in white, and the optional ones are in grey.

    For example:

    func foo(parameter1: Int = 0, parameter2: Int) {}
    

    enter image description here

    To insert all the parameters all at once, you can press option + enter, rather than just enter on its own, after selecting the overload using the arrow keys.

    * Upon further inspection, I think it's actually half-transparent, not grey.