Swift ios不确定我是否正确使用了完成处理程序

Swift ios不确定我是否正确使用了完成处理程序,ios,swift,Ios,Swift,当我登录到我的应用程序时,我将删除两个显示为模态的VC,然后添加一个新VC,并通过以下方式使其成为根VC: @IBAction func loginButtonDidTouch(sender: AnyObject) { let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let AccountVc = storyboard.instantiateViewControllerWithIden

当我登录到我的应用程序时,我将删除两个显示为模态的VC,然后添加一个新VC,并通过以下方式使其成为根VC:

@IBAction func loginButtonDidTouch(sender: AnyObject) {
    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

    let AccountVc = storyboard.instantiateViewControllerWithIdentifier("AccountVc")

    let navigationController = self.view.window?.rootViewController as! UINavigationController        

    self.presentingViewController!.presentingViewController!.dismissViewControllerAnimated(false) { () -> Void in                
        navigationController.setViewControllers([AccountVc], animated: true)                
    }
}
我要确保的是
navigationController.setViewControllers([AccountVc],动画:true)
运行一次
self.presentingViewController!。presentingViewController!。dismissViewControllerAnimated(false)
已完成

它是有效的,但我不确定这是否是正确的写作方式


我在写:
{()->Void in
我看到一些例子,人们只写而不写Void。

两种方法都是正确的。这称为
尾部闭包

func someFunctionThatTakesAClosure(closure: () -> Void) {
    // function body goes here
}

// here's how you call this function without using a trailing closure:

someFunctionThatTakesAClosure({
    // closure's body goes here
})

// here's how you call this function with a trailing closure instead:

someFunctionThatTakesAClosure() {
    // trailing closure's body goes here
}
更多信息请访问