Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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
Swift 关闭后如何返回?_Swift - Fatal编程技术网

Swift 关闭后如何返回?

Swift 关闭后如何返回?,swift,Swift,我如何在swift结束后返回 func closure(result: (Int -> Void)) { var next = 1 while (true) { result(next) } } 这是函数的调用 closure() { result in // here I need to return } 问题中的while循环没有返回。为了返回,必须有一些条件语句将退出while循环,例如: while (true) { re

我如何在swift结束后返回

func closure(result: (Int -> Void)) {
    var next = 1

    while (true) {
        result(next)
    }
}
这是函数的调用

closure() { result in
    // here I need to return
}

问题中的
while
循环没有返回。为了返回,必须有一些条件语句将退出while循环,例如:

while (true) {
   result(next)
   if something == false {
       break;
   }
}
或:

或:

var i=0
而<
印刷品(一)
}
var i = 0
while (true) {
    if i++ == 4 {
        break;
    }
    print(i)
}
var i = 0
while (i <
    print(i)
}