将两个具有相同名称的.swift文件添加到项目中

将两个具有相同名称的.swift文件添加到项目中

问题描述:

我正在尝试将swagger客户端集成到我的项目中。我能够从swagger生成类。 swagger for swift 3使用Alamofire进行新的操作。问题是生成的类名称之一是'Response'。 Alamofire内部拥有相同的级别。当我添加这些类并尝试构建时,我有很多错误抱怨重新声明类。在这种情况下我该怎么办?我是否必须从服务器端更改为响应类?

I am trying to integrate swagger client in my project. I was able to generate classes from swagger. Swagger for swift 3 uses Alamofire for its newtork operations. The issue is one of the generated class name is 'Response'. Alamofire internally has the same class. When i add these classes and try to build I have many errors complaining about re-declaration of class. What can i do in this case? Should i have to change from my server side to not get 'Response' class?

您应该可以保留其代码单独添加模块名称即可:

You should be able to leave their code alone and just add the module name to your calls:

Alamofire.Response.... Swagger.Response... 

以便您的代码不含糊。 (编译器不会尝试猜测你的意思,你已经给它了两种可能性......类的开头的模块名称将使编译器清楚你想要的那个。)

so that your code is not ambiguous. (the compiler won't try to guess which one you mean, and you've given it two possibilities... the Module name at the beginning of the class will make it clear to the compiler which one you want.)