Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';var';参数已弃用,将在Swift 3 UIimage Gif中删除_Swift_Swift3 - Fatal编程技术网

';var';参数已弃用,将在Swift 3 UIimage Gif中删除

';var';参数已弃用,将在Swift 3 UIimage Gif中删除,swift,swift3,Swift,Swift3,我刚刚将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

我刚刚将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
        }
    }
}
类函数gcdForPair(变量a:Int?,变量b:Int?->Int{
//检查其中一个是否为零
如果b==nil | | a==nil{
如果b!=nil{
返回b!
}否则,如果a!=零{
还一个!
}否则{
返回0
}
}
//模交换
如果a
更新:我重新编写了我的答案,因为我认为你实际上想要
输入,但你没有。所以

可以找到动机。tl;dr是:
var
inout
相混淆,它不会增加太多的价值,所以要摆脱它

因此:

func myFunc(var a: Int) {
    ....
}
变成:

func myFunc(a: Int) {
    var a = a
    ....
}
因此,您的代码将成为:

class func gcdForPair(a: Int?, _ b: Int?) -> Int {
    var a = a
    var b = b
    // 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
        }
    }
}
类函数gcdForPair(a:Int?,\b:Int?->Int{
变量a=a
变量b=b
//检查其中一个是否为零
如果b==nil | | a==nil{
如果b!=nil{
返回b!
}否则,如果a!=零{
还一个!
}否则{
返回0
}
}
//模交换
如果a
我试过了,但同样的问题至少你修复了我的大脑冻结,我用
let
代替
var
。但是,函数定义中没有
a:
。这就是导致您出现问题的原因吗?不,它在那里,但问题是修复程序告诉我删除它,在IBM的沙箱中,oOThis函数中没有var(我在这台机器上没有XCode)。也许可以尝试清理并重新启动XCode?顺便说一下,您可以在第一个
if
中缩短代码,以
返回a??B0
。我写了一个。(Bluemix在Safari中可能无法正常工作。)