Skip to content

Instantly share code, notes, and snippets.

@mehdok
Created December 8, 2018 10:05
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 mehdok/dd1f3c2c068848ab4129a377e1e8ec71 to your computer and use it in GitHub Desktop.
Save mehdok/dd1f3c2c068848ab4129a377e1e8ec71 to your computer and use it in GitHub Desktop.
import UIKit
public protocol StoryboardInitializable {
static var storyboardIdentifier: String { get }
}
public extension StoryboardInitializable where Self: UIViewController {
public static var storyboardIdentifier: String {
return String(describing: Self.self)
}
public static func initFromStoryboard(name: String = "Main") -> Self {
let storyboard = UIStoryboard(name: name, bundle: Bundle(for: self))
return storyboard.instantiateViewController(withIdentifier: storyboardIdentifier) as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment