Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

functions.swift
func getRemainder(a: Int , b: Int) {


}
return 

1 Answer

Jhoan Arango
Jhoan Arango
14,575 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(){
print("Hello")
}


// 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.
print("Hello,\(name)")
}

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

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

or 

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..