0

I was following optional values tutorial, in which we have following method

  func findIndexOfString (string : String, array : String[]) -> Int?{           
            for (index, value) in enumerate(array){             
                if(value == string){
                    return index
                }               
            }           
            return nil          
        }

however if i call this method by

let indexFound = findIndexOfString("myString", neighbour) //neighbour is array of String

give error that "Missing argument label ''array" in call , means i have to call this by

let indexFound = findIndexOfString("myString", array:neighbour)

Is it made compulsory to mention argument label in call?

BaSha
  • 2,356
  • 3
  • 21
  • 38

1 Answers1

1

Yeah. It is compulsory for for class methods. You should use the parameter names except for the first parameter. There comes the difference between the class methods and functions, for functions you will not use(You cant unless function defines an external parameter name) the parameter names.

Anil Varghese
  • 42,757
  • 9
  • 93
  • 110