替代方法:

private extension String {
    func convertToClass<T>() -> T.Type? {
        return StringClassConverter<T>.convert(string: self)
    }
}

private class StringClassConverter<T> {
    
    static func convert(string className: String) -> T.Type? {
        guard let nameSpace = Bundle.main.infoDictionary?["CFBundleExecutable"] as? String else {
            return nil
        }
        //TODO: 非标准命名的时候处理
        let name = "\(nameSpace)".replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: "-", with: "_")
        guard let aClass: T.Type = NSClassFromString("\(name).\(className)") as? T.Type else {
            return nil
        }
        return aClass
    }
}

使用:

let presenterType: CDDPresenter.Type? = "\(prefix)\(name)Presenter".convertToClass()
if let presenterType = presenterType {
  self.presenter = presenterType.init()
}