传递和返回功能
以下函数返回另一个函数作为其结果,稍后可以将其分配给变量并调用:
func jediTrainer () -> ((String, Int) -> String) {
func train(name: String, times: Int) -> (String) {
return "\(name) has been trained in the Force \(times) times"
}
return train
}
let train = jediTrainer()
train("Obi Wan", 3)