值类型和引用类型

值类型和引用类型
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( )








posted on 2017-06-18 18:40  ljbguanli  阅读(88)  评论(0编辑  收藏  举报