How to get class name of UIViewController Class in swift
In Objective C, we can do something like this :
self.appDelegate = (shAppDeleg
Expanding on juangdelvalle's answer.
I added this as an extension so that it's reusable and easier to call from any view controller. Also in some cases NSStringFromClass in Swift returns a string in the format like this:
< project name >.viewControllerClassName.
This extension property is modified to get rid of the project name prefix and return only the class name.
extension UIViewController {
var className: String {
NSStringFromClass(self.classForCoder).components(separatedBy: ".").last!
}
}