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