ios 类在两者中都实现。将使用两者之一

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30581884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:10:06  来源:igfitidea点击:

Class is implemented in both. One of the two will be used

iosobjective-cobjective-c-runtimesocketrocket

提问by MrGrinst

I have a project that has a dependency (installed via CocoaPods) using SocketRocket and have imported a static library from HeapAnalytics. Apparently the HeapAnalytics library already uses SocketRocket. I get no errors when compiling, but at runtime receive the following:

我有一个使用 SocketRocket 具有依赖项(通过 CocoaPods 安装)的项目,并从 HeapAnalytics 导入了一个静态库。显然 HeapAnalytics 库已经使用了 SocketRocket。编译时我没有收到错误,但在运行时收到以下信息:

Class SRWebSocket is implemented in both [path] and [path].
One of the two will be used. Which one is undefined.

I'm not sure how to handle it because most solutions I've seen require compiling the static library yourself change class names and such, and I don't have access to the source.

我不确定如何处理它,因为我见过的大多数解决方案都需要自己编译静态库来更改类名等,而我无权访问源代码。

Any recommendations?

有什么建议吗?

回答by bbum

I wrote that error message!?

我写了那个错误信息!?

Either change the class name or don't link against said library.

要么更改类名,要么不链接到所述库。

How is your project configured? Is there anywhere where you explicitly link against SR? Or is it a product of linking against two static libraries that both already include SR?

你的项目是如何配置的?有什么地方可以明确链接到 SR 吗?或者它是链接到两个都已经包含 SR 的静态库的产物?

If the former, then stop linking against SR directly and just inherit the version that came with the library already using it (warning: make sure it has the right version).

如果是前者,则停止直接与 SR 链接,只继承已经使用它的库附带的版本(警告:确保它具有正确的版本)。

If the latter, then you are going to have to modify one of the libraries.

如果是后者,那么您将不得不修改其中一个库。

? Actually, I modified the error. It used to imply that one or the other would be used. But that wasn't really what was going on and the behavior was different across different platforms. Thus, it was changed so that it was far more precise in identifying that the behavior was undefined.

? 实际上,我修改了错误。它曾经暗示将使用其中一个。但这并不是真正发生的事情,不同平台的行为也不同。因此,它进行了更改,以便更准确地识别行为未定义。

回答by user1046037

Overview:

概述:

The error suggests that the same symbol / class is defined twice.

该错误表明相同的符号/类被定义了两次。

Solution:

解决方案:

  • Check the frameworks linked to see if there are any duplicates. If so remove the duplicate
  • Clean build folder (Command + Shift + K)
  • If simulator, then reset the simulator and try
  • If device, restart the device and try
  • 检查链接的框架以查看是否有任何重复项。如果是这样,请删除重复项
  • 清理构建文件夹(Command + Shift + K)
  • 如果是模拟器,则重置模拟器并尝试
  • 如果设备,请重新启动设备并尝试

My experience:

我的经验:

I faced the same issue twice, once it was duplicate frameworks and the other time resetting simulator helped.

我两次遇到同样的问题,一次是重复的框架,另一次重置模拟器有帮助。

回答by Goodsquirrel

In my case this error appeared when I unnecessarily added a source file to both my main app target and my test target:

在我的情况下,当我不必要地将源文件添加到我的主应用程序目标和我的测试目标时,会出现此错误:

Target Membership with both targets selected

选择了两个目标的目标成员资格

Removing the test target from Target Membershipsolved it:

删除测试目标Target Membership解决了它:

Target Membership with only one target selected

仅选择一个目标的目标成员资格

回答by LukeSideWalker

I had this warning for more than a month, then I finally tried this and it worked for me:

我收到这个警告一个多月了,然后我终于尝试了这个,它对我有用:

  1. Resetthe simulator(Menu: Hardware -> Erase all content and settings ... )
  2. Cleanthe project (Command + Shift + K)
  3. Cleanthe build folder(Command + Option + Shift + K)
  4. Runthe code on the simulator again
  1. 复位模拟器(菜单:硬件- >删除所有内容和设置...)
  2. 清理项目(Command + Shift + K)
  3. 清洁build文件夹(命令+ Option + Shift键+ K)
  4. 再次在模拟器上运行代码