//证明函数和闭包是引用类型
//这是个返回了闭包的函数
func calcTotalMiles() -> (Int)->Int{
var totleMiles = 0
return { (todayMiles:Int) in
totleMiles = totleMiles + todayMiles;
return totleMiles
}
}
var myPlan1 = calcTotalMiles()
myPlan1(2)
myPlan1(4)
myPlan1(6)
var myPlan2 = myPlan1
myPlan2(1)
myPlan2(3)
myPlan2(5)
myPlan1(8)
Swift 闭包
最新推荐文章于 2024-08-29 16:05:23 发布