Jua*_*uan -1 iphone ipad ios swift ios9
我希望在一个方法完成后执行一个操作,我在其他方法中执行一个方法,我希望第二个方法停止,直到第一个方法完成.
我有这个方法:
func ejecutarOBJC(){
let txtNombre = self.view.viewWithTag(4) as? UITextField
let textoNombre=txtNombre?.text
let txtContra = self.view.viewWithTag(5) as? UITextField
let textoContra=txtContra?.text
let instanceOfCustomObject: SQLViewController = SQLViewController()
instanceOfCustomObject.nombre = textoNombre;
instanceOfCustomObject.contra = textoContra;
instanceOfCustomObject.obtenerExistenciaUsuario()
}
Run Code Online (Sandbox Code Playgroud)
还有另一种方法:
func otherMethod(){
ejecutarOBJC()
//I want continue with that method when the execution of the other method finish
}
Run Code Online (Sandbox Code Playgroud)
这就是你如何实现这个目标:
func methodOne() {
//Method one code here
methodTwo()
}
func methodTwo() {
//Method Two code here.
}
Run Code Online (Sandbox Code Playgroud)
根据您的评论,以下是使用异步代码时的等待方式:
func methodOne() {
//Code goes here
methodTwo { () -> () in
//Method two has finished
}
}
func methodTwo(completion: () -> ()) {
//Code goes here
completion()
}
Run Code Online (Sandbox Code Playgroud)