完成后添加功能((bool) - > void)

时间:2017-04-08 11:25:43

标签: ios swift

我想用完成处理程序调用此函数:

 public static void main (String [] args) 
 {
    String simonPattern = "";
    String userPattern = "";
    int userScore = 0;


    userScore = 0;
    simonPattern = "RRGBRYYBGY";
    userPattern  = "RRGBBRYBGY";

    String[] simons = new String[5];
    String[] users = new String[5];
    int adder=2;
    int location=0;
    for(int i=0;i<simonPattern.length();i+=2)
    {
        simons[location]=simonPattern.substring(i,adder);
        location++;
        adder+=2;
    }
    adder=2;
    location=0;
    for(int i=0;i<userPattern.length();i+=2)
    {
        users[location]=userPattern.substring(i,adder);
        location++;
        adder+=2;
    }



    for (int i = 0; i < simonPattern.length(); i++) 
    {
            if(users[i].equals(simons[i]))
                userScore++;



    }
    System.out.println(userScore);




    }

但是我收到错误:print produce()不是预期的上下文结果类型((bool) - &gt; Void)?

我不知道这个错误意味着什么。我只想在完成处理程序中持续时间结束时执行一个函数。我已经尝试过添加(Bool) - &gt;完成处理程序后无效,但这不起作用。谢谢。

1 个答案:

答案 0 :(得分:4)

签名SELECT unaccent('vietnamese', 'Hồ ầ phố'); -- ^~~~~~~~~~~~~ 的相应关闭是

(Bool) -> Void)

所以你必须写(省略冗余推断语法)

{ (result) -> Void in ... }

或使用尾随闭包语法

progressView.animate(fromAngle: 0, toAngle: 360, duration: 5, completion: { result in
    print("go to next lvl", result)
})

为什么不使用代码完成让Xcode为您提供正确的语法?