Skip to content

Instantly share code, notes, and snippets.

@cdzombak
Created January 22, 2015 00:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cdzombak/431cea0a4c0ced8042a5 to your computer and use it in GitHub Desktop.
public class Router : NSObject {
typealias VCPushBlock = (UIViewController) -> (Void)
init(context: NSManagedObjectContext, pushBlock: VCPushBlock) {
// ...
}
convenience init(context: NSManagedObjectContext, owningViewController: UIViewController) {
self.init(context: context, pushBlock: {
owningViewController.navigationController?.pushViewController($0, animated: true)
return Void()
})
}
// ...
}
@cdzombak
Copy link
Author

Note that line 11 has changed to an explicit return Void() (instead of the comment with the compiler's error message).

The optional method chaining on line 10 was returning a Void?, as it should. And though I always intended the block to return Void, this was a single-line block, so its inferred return type was that of its one line: Void?.

Adding the explicit return Void() allows the compiler to infer that the block does, in fact, return Void.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment