代码:
import Foundation
func swapTwoInts(a: inout Int, _ b: inout Int){
let temp = a
a = b
b = temp
}
var intA = 3
var intB = 5
print("int A is: \(intA), and int B is \(intB)")
swapTwoInts(a: &intA, &intB)
print("int A is: \(intA), and int B is \(intB)")
输出:
int A is: 3, and int B is 5
int A is: 5, and int B is 3
Program ended with exit code: 0