函数范型的基本使用

26. January 2016 Swift 0

var num1 = “1”,num2 = “2”  //使用范型定义函数的交换类型,使用inout和元祖交换两个数的值

func swapValue <T> (inout num1:T,inout num2:T){

(num1,num2) = (num2,num1)

}

swapValue(&num2, num2: &num1)

num1

num2


Leave a Reply

Your email address will not be published. Required fields are marked *