Swift functions perform tasks with data.
Functions organizes your code into small, repeatable chunks, like so:
func sayHello() { print("Hello") } sayHello()//from w ww. j a v a 2 s.c o m
Functions can return a value to the code that calls them.
When you define a function with return type, you must indicate the type by using the arrow -> symbol.
func usefulNumber() -> Int { return 123 //from w w w .jav a2 s. co m } let anUsefulNumber = usefulNumber() // 123 print(anUsefulNumber)