How to get class name of UIViewController
Class in swift
In Objective C, we can do something like this :
self.appDelegate = (shAppDelegate *)[[UIApplication sharedApplication] delegate]; UIViewController *last_screen = self.appDelegate.popScreens.lastObject ; if(last_screen.class != self.navigationController.visibleViewController.class){ //....... }
but in swift I tried like this
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate let last_screen = appDelegate.popScreens?.lastObject as UIViewController
cant do this.
if last_screen.class != self.navigationController.visibleViewController.class{ //.... }
no class method of UIViewController
i.e last screen
Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy. A view controller's main responsibilities include the following: Updating the contents of the views, usually in response to changes to the underlying data.
A UIViewController is an object which manages the view hierarchy of the UIKit application. The UIViewController defines the shared behavior and properties for all types of ViewController that are used in the iOS application. The UIViewController class inherits the UIResponder class. ADVERTISEMENT. ADVERTISEMENT.
An UIViewController is just the base class of this already defined "View Controller", you add a viewController as you said, but a viewController has a class associated to it, that can be a UIViewController, UITableViewController, or variations/subclasses.
To know your class name you can call something like this:
var className = NSStringFromClass(yourClass.classForCoder)
The cleanest way without needing to know the name of your class is like this.
let name = String(describing: type(of: self))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With