相关疑难解决方法(0)

嵌套函数在swift中的实际用途是什么?

嵌套函数的实际用途是什么?它只会使代码更难阅读,并且不会使特定情况变得容易.

func chooseStepFunction(backwards: Bool) -> (Int) -> Int {
    func stepForward(input: Int) -> Int { return input + 1 }
    func stepBackward(input: Int) -> Int { return input - 1 }
    return backwards ? stepBackward : stepForward
}
Run Code Online (Sandbox Code Playgroud)

资源

function swift

15
推荐指数
2
解决办法
5093
查看次数

标签 统计

function ×1

swift ×1