First time here? Get started in my Swift guide.
Functions are coded to perform actions and manipulate variables. They are part of a core component in programming. In Swift, functions are very simple to write and, if you have a basis of Object Oriented Programming, you can reuse them throughout your program.
Functions are used in all sorts of programs. You can write a function to calculate the number of calories you ate this morning
(I ate a lot, btw), how many miles you should run to burn them or even if you can purchase a book using your credit card!
Defining a function
In Swift and other programming languages, a function is defined by using the func keyword followed by its name, optional parameters, execution path and a return value. Continue reading “How to write a function in Swift”