如何在Swift中获取UIViewController
类的类名?
在Objective-C中,我们可以这样做:
self.appDelegate = (shAppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *last_screen = self.appDelegate.popScreens.lastObject ;
if(last_screen.class != self.navigationController.visibleViewController.class){
//.......
}
但是在 Swift 中我尝试了:
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let last_screen = appDelegate.popScreens?.lastObject as UIViewController
无法完成此操作。
if last_screen.class != self.navigationController.visibleViewController.class {
//....
}
UIViewController没有class
方法,即最后一个屏幕。
<project_name>.<class_name>
,但在大多数情况下用户只需要第二部分。 - Gargo