Member-only story

Intro to Functions in Swift

Jay Wilson
3 min readNov 8, 2019

Functions in Swift Series

Functions in Swift — Introduction

This post is going to explain what a function is and how to use it. It is a basic look at the parts of a function. More detail will be given in other posts.

Topics covered in this post

What is a Function

According to the Swift documentation, “functions are self-contained chunks of code that perform a specific task.”

Usually a function is defined when the task needs to be repeated or used somewhere else.

How to define a function

When defining a function, it needs to start with func. This tells the swift compiler that the next chunk of code is going to be a function. Then it needs an argument name followed by parentheses. Inside the parentheses, is where parameters go.

Function parameters are not required for a function. Parameters are necessary when the task needs data not accessible by the function. All parameters in a function must have a unique name. When using the parameters in the function, the parameter name is used to access the value it contains.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jay Wilson
Jay Wilson

Written by Jay Wilson

I like to solve problems using Swift, make YouTube videos, and take photos. I also really enjoy a good cup of coffee.

No responses yet

Write a response