Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Closures Functions as First Class Citizens Higher Order Functions

Anthony Westphal
Anthony Westphal
2,174 Points

Code works in Xcode but not here

Hi

I am able to run this code nicely in Xcode but not on tree house. Just wondering what i have missed

higherOrderFunctions.swift
/** 
  For this code challenge, let’s define a math operation as a function that 
  carries out some work on two integers and returns an integer as well. An 
  example is the function below, `differenceBetweenNumbers`, which takes two 
  integers and calculates the difference between the numbers. After calculating, 
  it returns the difference.
*/

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

// Enter your code below

func mathOperation(someFunc: ((Int , Int) -> (Int)) , c: Int , d: Int) -> (Int) {
   return someFunc(c , d)

}

let difference = mathOperation(differenceBetweenNumbers, 2, 1 )

1 Answer

Matthew Young
Matthew Young
5,133 Points

I'm not sure if this was present when you were submitting your code, but "-&g t;" should be replaced with "->".

Second, Xcode should have forced you to include the parameter names for your second and third parameter in the "mathOperation". If you include more than one parameter for your function, you have to include the name for the second parameter and on. I'm assuming it could do with that as well.

Otherwise, your code looks fine to me aside from those two observations.

Anthony Westphal
Anthony Westphal
2,174 Points

thanks, i don't know why my arrows changed. unfortunately neither of your observations were accepted by the tree house window

Matthew Young
Matthew Young
5,133 Points

What does the error say when you try submitting the code?