一次又一次检查条件,直到它成为现实

时间:2016-07-30 09:11:54

标签: ios swift

我想在执行一些代码之前在我的代码中添加recursioN func检查。那个检查一次又一次地重复,直到它成真为止。当条件为真时,它继续下一行并执行我的进一步代码。我不想使用while循环。我在seder.tag中使用audioControlButtonAction,因此我无法将所有代码添加到Internet connection OK时调用的另一个函数中。任何人都知道如何做到这一点。 感谢

func audioControlButtonAction(sender: UIButton){
// Here i want to add an Internet Reachability it repeats until it gets true

// Execute my code after condition will be true

}

    func recursioN(){

            if Reachability.isConnectedToNetwork() == true {
                print("Internet connection OK")
            } else {
                showAlert()
                print("Internet connection FAILED")
            }
        }

        func showAlert(){
            let createAccountErrorAlert: UIAlertView = UIAlertView()

            createAccountErrorAlert.delegate = self

            createAccountErrorAlert.title = "No Internet Connection"
            createAccountErrorAlert.message = "Make sure your device is connected to the internet."
            createAccountErrorAlert.addButtonWithTitle("Dismiss")
            createAccountErrorAlert.addButtonWithTitle("Retry")

            createAccountErrorAlert.show()
        }

        func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){

            switch buttonIndex{

            case 1:
                recursioN()
                NSLog("Retry")
                break;
            case 0:
                NSLog("Dismiss");
                break;
            default:
                NSLog("Default");
                break;
                //Some code here..

            }
        }

0 个答案:

没有答案