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

Local and external names?

Hey guys, can anyone please help me out with this question? Thanks!

functions.swift
// Enter your code below
func getRemainder(aValue value: Int, bDivisor divisor: Int) -> Int {

}

1 Answer

David Papandrew
David Papandrew
8,386 Points

If you want an external and internal name, you list the external name followed by a space and then the internal name and then the type.

func getRemainder(value a: Int, divisor b: Int) -> Int {
  return a % b
}

To call the function you would write: getRemainder(value: 10, divisor: 2)

Compare this to a version of the function with one name per parameter:

func getRemainder(a: Int, b: Int) -> Int {
 return a % b
}

Or this example might make it easier to understand:

func getRemainder(externalA internalA: Int, externalB internalB: Int) -> Int {
  return internalA % internalB
}
getRemainder(externalA: 10, externalB: 2)

Hope that helps.