How to get class name of UIViewController
Class in swift
In Objective C, we can do something like this :
self.appDelegate = (shAppDeleg
Here is a swift3 version of isuru's answer.
extension UIViewController {
var className: String {
return NSStringFromClass(self.classForCoder).components(separatedBy: ".").last!;
}
}
Swift 4
Suppose we have class with name HomeViewController
. Then you can get name of class with the following code:
let class_name = "\(HomeViewController.classForCoder())"
The classForCoder()
method returns AnyClass
object (name of your class) which we convert to string for user.
To know your class name you can call something like this:
var className = NSStringFromClass(yourClass.classForCoder)