码迷,mamicode.com
首页 > 其他好文 > 详细

值类型和引用类型

时间:2015-03-19 11:36:21      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:swift   blog   闭包      

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


技术分享


技术分享




值类型和引用类型

标签:swift   blog   闭包      

原文地址:http://blog.csdn.net/sinat_24436879/article/details/44453255

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!