Skip to content

Instantly share code, notes, and snippets.

@sandofsky
Created April 27, 2016 18:01
Show Gist options
  • Save sandofsky/0a8b5977afb16af1c6083fe97f0ac867 to your computer and use it in GitHub Desktop.
Save sandofsky/0a8b5977afb16af1c6083fe97f0ac867 to your computer and use it in GitHub Desktop.
import UIKit
protocol StoryboardBacked:class {
static func newFromStoryboardWithName(name:String?, bundle:NSBundle?) -> Self
}
extension StoryboardBacked {
static func newFromStoryboardWithName(name:String?, bundle:NSBundle?) -> Self {
let realName = name ?? NSStringFromClass(self as AnyClass).componentsSeparatedByString(".").last!
let storyboard = UIStoryboard(name: realName, bundle: bundle)
let controller = storyboard.instantiateInitialViewController()! as! Self
return controller
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment