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 Capturing Variables

Will Matthews
Will Matthews
8,127 Points

Also stuck on Higher-Order function challenge...

I'm also running a problem with the challenge review. I passed challenge 1 with the following:

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

However, challenge 2 keeps telling me: Bummer! Make sure you are computing the difference between two integers using the functions created and assigning the result to a constant named difference.

However, all I've done is set the following:

let difference = mathOperation(differenceBetweenNumbers, 10, 4)

This should work, no? It works fine in X Code, so what is the Treehouse reviewing mechanism looking for?

6 Answers

Hi Will,

Interestingly enough, just remove the parentheses from the first parameter's return type and it should work fine.

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

As for the reason, I have no idea. If you'd ask me, I'd leave the parentheses there and also put a pair of parentheses to the return type of mathOperation as well since the given differenceBetweenNumbers function's type is declared like that. But that didn't work either, so here we are.

Piers FC
Piers FC
10,402 Points

Treehouse really sucks sometimes. Not enough examples to practice and lots of bugs and not updated to Swift 2.0. better places to learn.

TreeHouse could be great but is at times extremely frustrating and has probably been a massive waste of money and time

Florian Groussin
Florian Groussin
4,563 Points

god you think ? where should I learn best ?

Will Matthews
Will Matthews
8,127 Points

Yup, that did the trick for me too! I don't get it either, but then I'm not 100% clear on how the treehouse editor does it's evaluating. I'm chalking it up to a glitch in how the answer was recorded. :) Thanks!

Here is my accepting code for challenge task 1 of 2.

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

// Enter your code below
func mathOperation(mathFunc: (Int, Int) -> Int, a: Int, b: Int) -> Int
{
return mathFunc(a, b)
}
Austin Smith
STAFF
Austin Smith
Treehouse Guest Teacher

Thanks Alp Eren Can! I had the same issue, and you fixed it. Thanks so much!

Hey there Pasan Premaratne are you aware of this issue? Removing the parenthesis from mathOperation return type allows for the Treehouse editor to accept to answer. I think this is a bug... see code comments above. Thanks! Keep up the great work. You guys ROCK!

Rafael Schwemmer
Rafael Schwemmer
6,109 Points

I also had the same problem. Thanks everyone. They should fix it!