Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 任意のUIViewControllerのサブクラスに対して、Storyboardableを適応することによって、
- Storyboardから該当のUIViewControllerの型でインスタンスを取得できるようになります。
- */
- extension NSObjectProtocol {
- static var className: String {
- return String(describing: self)
- }
- }
- protocol Storyboardable: NSObjectProtocol {
- static var storyboardName: String { get }
- static func instantiate() -> Self
- }
- extension Storyboardable where Self: UIViewController {
- static var storyboardName: String {
- return className
- }
- static func instantiate() -> Self {
- return UIStoryboard(
- name: storyboardName,
- bundle: Bundle(for: self)
- ).instantiateInitialViewController() as! Self
- }
- }
Add Comment
Please, Sign In to add comment