import UIKit
protocol SegueHandler {
associatedtype SegueIdentifier: RawRepresentable
}
extension SegueHandler where Self: UIViewController, SegueIdentifier.RawValue == String {
func performSegue(withIdentifier identifier: SegueIdentifier, sender: Any?) {
performSegue(withIdentifier: identifier.rawValue, sender: sender)
}
func shouldPerformSegue(withIdentifier identifier: SegueIdentifier, sender: Any?) -> Bool {
return shouldPerformSegue(withIdentifier: identifier.rawValue, sender: sender)
}
func segueIdentifier(for segue: UIStoryboardSegue) -> SegueIdentifier {
guard let identifier = segue.identifier, let segueIdentifier = SegueIdentifier(rawValue: identifier) else {
fatalError("Invalid segue identiifer \(segue.identifier ?? "NaN")")
}
return segueIdentifier
}
func segueIdentifier(for identifier: String?) -> SegueIdentifier {
guard let str = identifier, let segueIdentifier = SegueIdentifier(rawValue: str) else {
fatalError("Invalid segue identiifer \(identifier ?? "NaN")")
}
return segueIdentifier
}
}
Last active
April 25, 2017 17:38
-
-
Save alexj70/29b245c19092e78d0902d1bb38922bf5 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment