我刚刚将 Xcode 更新到 7.3,现在我收到了这个警告:
'var' 参数已弃用,将在 Swift 3 中删除
我需要在这个函数中使用 var:
class func gcdForPair(var a: Int?, var _ b: Int?) -> Int {
// Check if one of them is nil
if b == nil || a == nil {
if b != nil {
return b!
} else if a != nil {
return a!
} else {
return 0
}
}
// Swap for modulo
if a < b {
let c = a
a = b
b = c
}
// Get greatest common divisor
var rest: Int
while true {
rest = a! % b!
if rest == 0 {
return b! // Found it
} else {
a = b
b = rest
}
}
}