Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.