Skip to content

Instantly share code, notes, and snippets.

@alobanov
Last active January 22, 2016 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alobanov/10f75deb3bbbf2cc2b49 to your computer and use it in GitHub Desktop.
Save alobanov/10f75deb3bbbf2cc2b49 to your computer and use it in GitHub Desktop.
Simple creating viewcintroller instance by instantiateViewControllerWithIdentifier
class SimpleViewController: UIViewController, StoryboardInstantiable{
typealias ViewController = SimpleViewController
static var storyboardID: String { get { return "SimpleViewController" } }
override func viewDidLoad() {
super.viewDidLoad()
}
}
import Foundation
protocol StoryboardInstantiable {
typealias ViewController
static var storyboardID: String { get }
static func instance(storyboard: UIStoryboard) -> ViewController?
static func instance(storyboardName: String) -> ViewController?
}
extension StoryboardInstantiable {
static func instance(storyboard: UIStoryboard) -> ViewController? {
return storyboard.instantiateViewControllerWithIdentifier(Self.storyboardID) as? ViewController
}
static func instance(storyboardName: String) -> ViewController? {
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
return storyboard.instantiateViewControllerWithIdentifier(Self.storyboardID) as? ViewController
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment