值类型和引用类型

前端之家收集整理的这篇文章主要介绍了值类型和引用类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
值类型和引用类型
import UIKit


func trytochangeValue( var x:Int ){x++}
var a:Int = 2
tyrChangeValue(a)
a


var b:Int = a
b
b++
b
a


Value Type and Reference Type
Int,Float,Double,Bool


Tuple
-> Value Type
String,Array,Dictionary


Function,Closure -> Reference Type




import UIKit


func calcTotalMiles( todayMiles:Int ) -> ( ) -> Int{
var totalMiles = 0
return {totalMiles += todayMiles; return totalMiles;}
}


var dailyTwoMiles = calcTotalMiles(2)
dailyTwoMiles()
dailyTwoMiles()
dailyTwoMiles()


var dailyThreeMiles = calcTotalMiles(3)
dailyThreeMiles( )
dailyThreeMiles( )
dailyThreeMiles( )


var myPlan = dailyTwoMiles
maPlan()


dailyTwoMiles( )




原文链接:https://www.f2er.com/swift/327462.html

猜你在找的Swift相关文章