Created
June 30, 2016 06:05
-
-
Save tempire/e0330d6dfb99c4bf5581f446d4486e1b to your computer and use it in GitHub Desktop.
Typed view controller and storyboard
This file contains 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
// Allows | |
// Storyboard.Main.viewController(MainVC) | |
enum Storyboard: String { | |
case Main | |
static let values = [Main] | |
static var boards = [Storyboard:UIStoryboard]() | |
func viewController<A: UIViewController>(type: A.Type) -> A { | |
return storyboard.instantiateViewControllerWithIdentifier("\(A.self)") as! A | |
} | |
var storyboard: UIStoryboard { | |
var storyboard: UIStoryboard! | |
if let value = Storyboard.boards[self] { | |
storyboard = value | |
} | |
else { | |
storyboard = UIStoryboard(name: rawValue, bundle: .None) | |
Storyboard.boards[self] = storyboard | |
} | |
return storyboard | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment