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

Here is my latest answer for task 2: let difference = mathOperation(differenceBetweenNumbers,3,5) What is the problem?

I cannot pass the exam. What's wrong?

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

// Enter your code below
func mathOperation(aFunc:(Int, Int) -> (Int),firstInt:Int,secondInt:Int) -> (Int){
    return aFunc(firstInt,secondInt)
}

let difference = mathOperation(differenceBetweenNumbers,3,5)

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Use this code for the function, gets rid of some of the parentheses around the returns:

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

Thank you, it worked :) It's about the compiler and some empty spaces issue I think..

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

I don't know that this code is any different but try copy and pasting it.

let difference = mathOperation(differenceBetweenNumbers, 2, 1)

Unfortunately, it did not work. I cannot pass the Swift Closure exam because of this problem.