Swift Function Parameter and Return ValueThe Swift 4 user-defined function can have multiple parameters and different return values. a) Functions with no parameter and no return valueThe Swift 4 functions with no parameter and no return value do not take any input and return value. Syntax:Example:Output: Good Morning Everyone b) Functions with no parameters but having return valueExample:Output: Good Morning Everyone In the above program, the return type is String. Now, the statement must return a string from the statement inside the function, otherwise it will give an error. The return keyword transfers control of the program from body of the function to the function call. To return value from the function, we have to add value after the return keyword. c) Function with Parameter but having no return valueIn Swift 4, some functions have parameters but don?t have return value. Parameters are used to take input in the function. Syntax:Example:Output: Good Morning Everyone In the above program, the function accepts a single parameter of type String. The parameter can only be used inside the function. You can call the function by passing it a string value with the parameter name as greeting(msg: "Good Morning Evryone"). The msg parameter name is visible only inside the function greeting(). After that, the statement print(msg) gives the output Good Morning Everyone. d) Functions with Parameter and Return ValueWhen a function takes parameters and also returns value. Syntax:Example:Output: Welcome to JavaTpoint Ajeet You can see that in the above program, the function accepts a single parameter of type String and also returns value Welcome to JavaTpoint Ajeet of type String. e) Function with multiple parameters and multiple return valuesThese functions are used to take multiple parameters separated by comma and return multiple return values. In Swift, tuples are used to return multiple values. Syntax:Example:Output: Hello Mr./Ms.Ajeet You have 20 coins left in your wallet. Next TopicSwift Recursion |