3

Here is the code in objective-c:

[self presentViewController:logInViewController animated:YES completion:NULL];

My code so far in swift:

self.presentViewController(logInViewController, animated: true, completion:  )

Thought it would be as straight forward as typing "Void". Unfortunately there's a little more to it.

LondonGuy
  • 10,778
  • 11
  • 79
  • 151
  • 5
    Wouldn't `nil` work? – Kevin DiTraglia Sep 02 '14 at 13:14
  • @KevinDiTraglia Originally tried but it didn't work but now I can see it was an autocomplete problem. The autocomplete in XCode 6 is a little funky. Haven't got used to it. – LondonGuy Sep 02 '14 at 13:17
  • 1
    You should use nil for both Swift [and Objective C](http://stackoverflow.com/a/5766292/300836). It's sensible, *and* it's easy to remember... – Matt Gibson Sep 02 '14 at 14:49
  • But, `nil` can only be used if the completion block is optional. In this specific case (probably in most UIKit cases) the block is invoked as `(()->Void)!` so it's an explicitly unwrapped optional and takes nil. – David Berry Sep 02 '14 at 15:27

1 Answers1

4

Apple's prerelease documentation says:

func presentViewController(_ viewControllerToPresent: UIViewController!,
                                       animated flag: Bool,
                               completion completion: (() -> Void)!)

Parameters

viewControllerToPresent

The view controller to display over the current view controller’s content.

flag

Pass true to animate the presentation; otherwise, pass false.

completion

The block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.

Therefore you can specify nil for this parameter.

You can access this prerelease documentation from your iOS Dev Center

Goppinath
  • 10,569
  • 4
  • 22
  • 45