O'Reilly logo

Learning iOS 8 Game Development Using Swift by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Functions

A function is a block of code that is used to perform a certain task. It can be used to assign a block of reusable code that you can call again and again without rewriting the code every time to perform that task.

Simple functions

Functions in Swift are written as follows:

func someFunction(){

Println(" performing some function ")

} 

So here, before a function, we will need to use the func keyword, followed by the name of the function, the parentheses, and the open and closed curly braces.

Calling a function here is very similar to any other language, that is, the name of the function followed by parentheses:

someFunction() 

Passing a parameter

Now, to perform some task on a variable passed to a function, we first need to pass a parameter into ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required