Guest User

Untitled

a guest
May 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /*
  2. 任意のUIViewControllerのサブクラスに対して、Storyboardableを適応することによって、
  3. Storyboardから該当のUIViewControllerの型でインスタンスを取得できるようになります。
  4. */
  5. extension NSObjectProtocol {
  6. static var className: String {
  7. return String(describing: self)
  8. }
  9. }
  10. protocol Storyboardable: NSObjectProtocol {
  11. static var storyboardName: String { get }
  12. static func instantiate() -> Self
  13. }
  14. extension Storyboardable where Self: UIViewController {
  15. static var storyboardName: String {
  16. return className
  17. }
  18. static func instantiate() -> Self {
  19. return UIStoryboard(
  20. name: storyboardName,
  21. bundle: Bundle(for: self)
  22. ).instantiateInitialViewController() as! Self
  23. }
  24. }
Add Comment
Please, Sign In to add comment