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
}
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()
}