Skip to content

Instantly share code, notes, and snippets.

@onevcat
Last active January 12, 2016 03:49
Show Gist options
  • Save onevcat/7f5391f3f8dcf5d73473 to your computer and use it in GitHub Desktop.
Save onevcat/7f5391f3f8dcf5d73473 to your computer and use it in GitHub Desktop.
public func tr_pushViewController<T where T: TRTransition, T.Content == UIViewController>(viewController: T, method: TRPushMethod, statusBarStyle: TRStatusBarStyle = .Default, completion: (() -> Void)? = nil) {
guard let vc = viewController as? T.Content else {
fatalError()
}
let transitionDelegate = TRNavgationTransitionDelegate(method: method, status: .Push, gestureFor: vc)
transitionDelegate.completion = completion
viewController.tr_transition = transitionDelegate
delegate = transitionDelegate
transitionDelegate.previousStatusBarStyle = TRStatusBarStyle.CurrentlyTRStatusBarStyle()
transitionDelegate.currentStatusBarStyle = statusBarStyle
pushViewController(vc, animated: true)
}
protocol TRTransition {
typealias Content = Self
}
extension UIViewController: TRTransition {
}
extension Int: TRTransition {
}
func miao<T where T: TRTransition, T.Content == UIViewController>(param: T) {
let p = param as! UIViewController
print(p.dynamicType)
}
miao(UIViewController()) // This is OK
miao(UITableViewController()) // This is also OK
miao(1) // Will not compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment