Llg Llg - 16 days ago 5
Objective-C Question

Swift: Dismiss viewController 1 then present viewController 2

I want to dismiss a loader view controller then present an

UIDocumentInteractionController
. I found an objective-c solution, but I want the Swift 3 one.

This is the objective-c code taken from this answer:

// Does not break
[viewController1 dismissViewControllerAnimated:YES completion:^{
[self presentViewController:viewController2 animated:YES completion:NULL];
}];


I translated like this in Swift 3:

self.dismiss(animated: false, completion:{
self.docController = UIDocumentInteractionController(url: destinationUrl!)
self.docController!.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

})


It works fine, but I want to be sure that the
completion:^{
in objective-c means
completion:{
in Swift 3.

Answer

Yes, your assumption is correct. Though you don't need to write completion explicitly in Swift 3.

You can write something like this too.

self.dismiss(animated: false) { 
    self.docController = UIDocumentInteractionController(url: destinationUrl!)
    self.docController!.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
}
Comments