Learn
Functions
Review

Excellent work! 👏 In this lesson, you’ve covered a major fundamental programming concept used in the majority of all programs to organize code into reusable blocks.

Here’s a recap:

  • A function definition consists of a function name followed by optional parameters and a return type.
  • The function body holds the function’s task.
  • A function will execute only when it is called.
  • A return keyword is used to return a value from a function.
  • A function’s return type is specified in the function definition followed by an ->. If a function does not return any values, it’s return type is Void or the arrow and type are omitted entirely.
  • A return statement can be omitted if the function consists of only one expression to return. This is called an implicit return.
  • A parameter is a placeholder for a real value passed into a function. A parameter must be enclosed within () of a function definition and must have a specific type.
  • An argument is a real value passed in for a parameter in the function call.
  • A function can accept multiple parameters separated by commas. As many parameters as a function accepts, as many arguments or real values must be passed into the function when it is called.
  • A function can return multiple values in the form of a tuple.
  • Swift offers support for wide variety of parameter use cases within a function:
    • Default Parameter: a parameter that sets a value to the parameter that will be used if an argument is omitted.
    • Variadic Parameter: a parameter that accepts zero or more values of the parameter’s type.
    • In-out Parameter: a parameter whose value is passed into a function and modified within the body.

Instructions

Click Up Next when you’re ready to move on.

Folder Icon

Take this course for free

Already have an account?