【发布时间】:2014-06-13 18:19:01
【问题描述】:
我怀疑我在这里遗漏了一些非常明显的错误,所以如果我有点厚,请原谅我。
我看到的所有闭包示例都是将闭包传递给数组映射函数。我想编写自己的函数,它需要一个闭包
这就是我正在尝试的
func closureExample(numberToMultiply : Int, myClosure : (multiply : Int) -> Int) -> Int
{
// This gets a compiler error because it says myClosure is not an Int
// I was expecting this to do was to invoke myClosure and return an Int which
// would get multiplied by the numberToMultiply variable and then returned
return numberToMultiply * myClosure
}
我完全被自己做错了什么难住了
请帮忙!!
【问题讨论】:
-
试试
return numberToMultiply * myClosure(1)