Skip to content

Instantly share code, notes, and snippets.

@eugeniobaglieri
Created November 10, 2015 18:07
Show Gist options
  • Save eugeniobaglieri/5bc8969bfc60bb8d4f4d to your computer and use it in GitHub Desktop.
Save eugeniobaglieri/5bc8969bfc60bb8d4f4d to your computer and use it in GitHub Desktop.
//
// UIViewController+Storyboard.swift
// Temi Svolti
//
// Created by Eugenio Baglieri on 10/11/15.
// Copyright © 2015 Eugenio Baglieri. All rights reserved.
//
import UIKit
protocol StoryboardIdentifiable {
static var storyboardIdentifier: String {get}
}
extension UIViewController: StoryboardIdentifiable {
static var storyboardIdentifier: String {
let classString = NSStringFromClass(self)
let components = classString.componentsSeparatedByString(".")
assert(components.count > 0, "Failed extract class name from \(classString)")
return components.last!
}
}
extension UIViewController {
class func instantiateFromStoryboard<T: UIViewController>(storyboard: UIStoryboard) -> T {
return storyboard.instantiateViewControllerWithIdentifier(T.storyboardIdentifier) as! T
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment