iOS Functions in Swift Adding Power to Functions Function Parameters

i thin i missed important point what is parameters and how i am gonna use it

what is parameters and how i am gonna use it in functions

func getRemainder(a: Int , b: Int) {


1 Answer

Jhoan Arango
Jhoan Arango
Treehouse Moderator 13,603 Points

Hello Kerim,

Parameters are part of the function's functionality. You add parameters in order for you to be able to pass in "Arguments".

Let me show you:

// Function with no parameters

func sayHello(){

// Calling the function

sayHello() // Will print "Hello"

With the function "sayHello()" every time you call it, it will print "Hello", and that's it. It will not do anything else other than that. But what if I want to use the same function but I want it to say "Hello, Kerim" Or any other name?

We can add a Parameter in order for us to be able to do such thing.

// Function with one Parameter

func sayHello(to name: String) {

// Let's use the parameter "name" using string interpolation.

// Calling the function and passing a string value after the argument label "to"..

sayHello(to: "Kerim") // Will print "Hello, Kerim"


sayHello(to: "Jhoan") // Will print "Hello, Jhoan"

For more information refer to "The Swift Programming language" by apple.

Click on this link

Hope this helps you..