Created
November 10, 2015 18:07
-
-
Save eugeniobaglieri/5bc8969bfc60bb8d4f4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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