如何将NSClassFromString的代码转换为Swift?

时间:2015-04-20 07:02:43

标签: objective-c iphone swift ios7

UIViewController *viewController = [[NSClassFromString(viewControllerName) alloc] init];

如何将NSClassFromString的此代码转换为swift

1 个答案:

答案 0 :(得分:1)

你可以这样写:

if let viewController = NSClassFromString(viewControllerName) as? UIViewController.Type {
   // Do something 
}