Last active
January 22, 2016 19:17
-
-
Save alobanov/10f75deb3bbbf2cc2b49 to your computer and use it in GitHub Desktop.
Simple creating viewcintroller instance by instantiateViewControllerWithIdentifier
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
class SimpleViewController: UIViewController, StoryboardInstantiable{ | |
typealias ViewController = SimpleViewController | |
static var storyboardID: String { get { return "SimpleViewController" } } | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
} |
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
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