使用元组交换两个数据

func swapTwoInts( a: inout Int, b: inout Int) {
    (a, b) = (b, a)
}

var x = 1
var y = 2
swapTwoInts(a: &x, b: &y)
x    // 2
y    // 1

 

posted @ 2017-03-13 11:13  紫洁  阅读(555)  评论(0编辑  收藏  举报