Created
September 23, 2015 07:20
-
-
Save haldun/fab59bbb2334f10852ff to your computer and use it in GitHub Desktop.
SegueHandlerType
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SegueHandlerType.swift | |
// | |
import UIKit | |
protocol SegueHandlerType { | |
typealias SegueIdentifier: RawRepresentable | |
} | |
extension SegueHandlerType where Self: UIViewController, SegueIdentifier.RawValue == String { | |
func performSegueWithIdentifier(segueIdentifier: SegueIdentifier, sender: AnyObject?) { | |
performSegueWithIdentifier(segueIdentifier.rawValue, sender: sender) | |
} | |
func segueIdentifierForSegue(segue: UIStoryboardSegue) -> SegueIdentifier { | |
guard let identifier = segue.identifier, | |
segueIdentifier = SegueIdentifier(rawValue: identifier) | |
else { fatalError("Invalid segue identifier \(segue.identifier)") } | |
return segueIdentifier | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// | |
import UIKit | |
class ViewController: UIViewController, SegueHandlerType { | |
enum SegueIdentifier: String { | |
case ShowDetail = "ShowDetail" | |
} | |
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { | |
switch segueIdentifierForSegue(segue) { | |
case .ShowDetail: | |
print("Configure next view controller here") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment