swift 内嵌函数
函数 swift 内嵌
2023-09-27 14:27:38 时间
可以在函数内部定义另外一个函数。这就是内涵函数
内嵌函数在默认情况下在外部是被隐藏起来的。但却人人可以通过包裹他们的函数来调用他们。包裹的函数也可以返回内部的一个函内嵌函数来在另外的范围里使用
这个是java没有的语法,,
//: A UIKit based Playground for presenting user interface
import UIKit
func chooseStepFunction(backward:Bool)->(Int)->Int{
func stepForward(input:Int)->Int{
return input+1
}
func stepBackWard(input:Int)->Int{
return input-1
}
return backward ? stepBackWard : stepForward
}
var currentValue = -4
let moveNearerToZear = chooseStepFunction(backward: currentValue>0)
while currentValue != 0{
print("\(currentValue)...")
currentValue = moveNearerToZear(currentValue)
}
print("zero!")
-4...
-3...
-2...
-1...
zero!
相关文章
- C语言-基础语法(八):局部变量、静态局部变量、全局变量、静态全局变量、全局函数、静态函数【auto、extern、static、 register】
- 基于径向基函数 (RBF) 神经网络的麦基格拉斯时间序列预测(Matlab代码实现)
- OpenGL中常用的函数
- js去掉url后某参数【函数封装】
- 从零开始学C++之构造函数与析构函数(二):初始化列表(const和引用成员)、拷贝构造函数
- MySQL中FIND_IN_SET函数
- HDU3544 Alice's Game && POJ 2960 S-Nim(SG函数)
- IE不兼容ES6箭头函数的解决方法(在浏览器中使用)
- LeetCode·每日一题·636.函数的独占时间·栈模拟
- swift 高阶函数
- 011_swift_函数当做返回值。函数当做参数
- jQuery.parseHTML() 函数
- 【Visual C++】绘图函数BitBlt的使用方法
- 机器学习之路: tensorflow 自定义 损失函数
- python - # 此函数将指定文件移动到指定目录(os模块和shutil模块)