2
當函數的返回值是另一個函數時,無法獲得返回的函數的參數名稱。這是否是快捷語言的陷阱?在Swift中,沒有辦法獲得返回函數的參數名稱?
例如:
func makeTownGrand(budget:Int,condition: (Int)->Bool) -> ((Int,Int)->Int)?
{
guard condition(budget) else {
return nil;
}
func buildRoads(lightsToAdd: Int, toLights: Int) -> Int
{
return toLights+lightsToAdd
}
return buildRoads
}
func evaluateBudget(budget:Int) -> Bool
{
return budget > 10000
}
var stopLights = 0
if let townPlan = makeTownGrand(budget: 30000, condition: evaluateBudget)
{
stopLights = townPlan(3, 8)
}
謹記townPlan
,townPlan(lightsToAdd: 3, toLights: 8)
會更明智的townPlan(3, 8)
,對不對?