Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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 使用异步方法进行While循环_Swift_Asynchronous_Grand Central Dispatch - Fatal编程技术网

Swift 使用异步方法进行While循环

Swift 使用异步方法进行While循环,swift,asynchronous,grand-central-dispatch,Swift,Asynchronous,Grand Central Dispatch,我有麻烦了。我得到了一个方法,其中包含异步方法的while循环。问题是,虽然循环在异步任务完成之前完成,但我的方法会完成几次。所以我需要complete()只调用一次,当所有while循环都完成并且所有异步任务都已经完成时。有人能帮我吗?我找到了一些答案,但对我的问题毫无帮助 循环: let dispatchGroup = DispatchGroup() repeat { dispa

我有麻烦了。我得到了一个方法,其中包含异步方法的while循环。问题是,虽然循环在异步任务完成之前完成,但我的方法会完成几次。所以我需要complete()只调用一次,当所有while循环都完成并且所有异步任务都已经完成时。有人能帮我吗?我找到了一些答案,但对我的问题毫无帮助

循环:

                           let dispatchGroup = DispatchGroup()

            repeat {

                dispatchGroup.enter()

                var configSection = "@rule[\(rulesNumber)]"
                print(rulesNumber, rulesCount)


                Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configEnabledOption) { (response1) in
                    MethodsClass().getJsonValue(response_data: response1) { (enabledValue) in
                        Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configAnalogType) { (response2) in
                            MethodsClass().getJsonValue(response_data: response2) { (analogTypeValue) in
                                Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configTypeOption) { (response3) in
                                    MethodsClass().getJsonValue(response_data: response3) { (typeValue) in
                                        Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configTriggerOption) { (response4) in
                                            MethodsClass().getJsonValue(response_data: response4) { (triggerValue) in
                                                Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configActionOption) { (response5) in
                                                    MethodsClass().getJsonValue(response_data: response5) { (actionValue) in
                                                        Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configMinOption) { (response6) in
                                                            MethodsClass().getJsonValue(response_data: response6) { (minValue) in
                                                                Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configMaxOption) { (response7) in
                                                                    MethodsClass().getJsonValue(response_data: response7) { (maxValue) in
                                                                        Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configMinCOption) { (response8) in
                                                                            MethodsClass().getJsonValue(response_data: response8) { (minCValue) in
                                                                                Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configMaxCOption) { (response9) in
                                                                                    MethodsClass().getJsonValue(response_data: response9) { (maxCValue) in
                                                                                        Json().deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configOutPut) { (response10) in
                                                                                            MethodsClass().getJsonValue(response_data: response10) { (outPutNb) in




                                                                                                if (!enabledValue.isEmpty && !typeValue.isEmpty && !triggerValue.isEmpty && !actionValue.isEmpty) {
                                                                                                    object["Enabled"] = enabledValue
                                                                                                    object["Type"] = typeValue
                                                                                                    object["Trigger"] = triggerValue
                                                                                                    object["Action"] = actionValue

                                                                                                    object["AnalogType"] = analogTypeValue
                                                                                                    object["MinValue"] = minValue
                                                                                                    object["MaxValue"] = maxValue
                                                                                                    object["MinCValue"] = minCValue
                                                                                                    object["MaxCValue"] = maxCValue
                                                                                                    object["OutputNb"] = outPutNb
                                                                                                    arrayObjects.append(object)

                                                                                                }

                                                                                                if rulesNumber == rulesCount {
                                                                                                    print(rulesNumber, rulesCount, "f", arrayObjects)
                                                                                                   // complete(arrayObjects)
                                                                                                }

                                                                                            }}
                                                                                    }} }}}}  }}}}}}}}}}
                    }}
                rulesNumber += 1



                dispatchGroup.leave()

            dispatchGroup.wait(timeout: DispatchTime.distantFuture)
            } while (rulesNumber < rulesCount)

            dispatchGroup.notify(queue: DispatchQueue.main) {
                print(arrayObjects)
               complete(arrayObjects)

            }
让dispatchGroup=dispatchGroup()
重复{
dispatchGroup.enter()
var configSection=“@rule[\(rulesNumber)]”
打印(规则编号,规则搜索)
Json().DeviceInfo(令牌:token as!String,config:iomanConfig,节:configSection,option:ConfigEnableDopption){(response1)in
MethodsClass().getJsonValue(响应数据:response1){(enabledValue)在
Json().DeviceInfo(令牌:token as!String,config:iomanConfig,节:configSection,option:configAnalogType){(response2)in
MethodsClass().getJsonValue(响应数据:response2){(analogTypeValue)在
Json()
MethodsClass().getJsonValue(响应数据:response3){(类型值)在
Json()
MethodsClass().getJsonValue(响应数据:response4){(triggerValue)在
Json()
MethodsClass().getJsonValue(响应数据:response5){(actionValue)在
Json()
MethodsClass().getJsonValue(响应数据:response6){(最小值)在
Json()
MethodsClass().getJsonValue(响应数据:响应7){(最大值)在
Json()
MethodsClass().getJsonValue(响应数据:响应8){(最小值)在
Json()
MethodsClass().getJsonValue(响应数据:响应9){(最大值)在
Json()
MethodsClass().getJsonValue(响应数据:response10){(outPutNb)在
如果(!enabledValue.isEmpty&&!typeValue.isEmpty&&!triggerValue.isEmpty&&!actionValue.isEmpty){
对象[“Enabled”]=enabledValue
对象[“类型”]=类型值
对象[“触发器”]=triggerValue
对象[“操作”]=操作值
对象[“AnalogType”]=analogTypeValue
对象[“MinValue”]=MinValue
对象[“MaxValue”]=MaxValue
对象[“MinCValue”]=MinCValue
对象[“MaxCValue”]=MaxCValue
对象[“OutputNb”]=OutputNb
ArrayObject.append(对象)
}
如果rulesNumber==ruleScont{
打印(规则编号,规则搜索,“f”,阵列对象)
//完成(阵列对象)
let dispatchGroup = DispatchGroup()
repeat {
    // ...
    dispatchGroup.enter()
    deviceinform(token: token as! String, config: iomanConfig, section: configSection, option: configEnabledOption) { (response1) in
        // ...
        dispatchGroup.leave()
    }
}

dispatchGroup.notify(queue: DispatchQueue.main) {
    complete()
}