Michael Malek
Michael Malek

Reputation: 41

Calling Methods of Structs in Swift

When coding in Swift, if I call a method of a struct and the method has only one parameter do I need to state the label of the parameter or only the value?

Upvotes: 1

Views: 748

Answers (1)

Midhun MP
Midhun MP

Reputation: 107131

That depends on your implementation.

Implementation 1:

If your implementation is something like this:

func myMethod(myParam: String) -> String
{
    return "Midhun is \(myParam)"
}

You can call the method like:

yourObj.myMethod("good");

Implementation 2

If your implementation have explicit argument name, like:

func myMethod(character myParam: String) -> String
{
    return "Midhun is \(myParam)"
}

You need to call it using:

yourObj.myMethod(character: "good");

Upvotes: 2

Related Questions