Member-only story
A Deep Dive Into Functions in Swift
From closures to higher-order functions, we’ve got it all covered
By and large, functions are a basic component of any programming language and is one of the first things that you learn when you start to code as well. In this article we’ll go through the basics and then also delve into some of their details.
Basics: Functions and Closures
Functions and Closures are both constructs provided by Swift to perform a set of tasks within itself. They take in 0 or more parameters which might be needed to performs the tasks and they can optionally return a value.
Functions
Let’s start with functions, since they’re easier to understand.
There are five parts to a function:
- The keyword
func
. This keyword signifies the start of a function definition. - The name of the function.
- The parameters (named or un-named)
- The body of the function.
- The return type followed by a
->
eg:-> String