xcode Cocoapods:重复的接口定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28746129/
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-09-15 06:43:50  来源:igfitidea点击:

Cocoapods: duplicate interface definition

iosxcodeswiftxcode6cocoapods

提问by Mikhail

I' wrapped mine private library into cocoapods. It has dependency on ReactiveCocoa.

我把我的私人图书馆包装成可可豆。它依赖于 ReactiveCocoa。

s.name =  'MineLibrary'
s.dependency 'ReactiveCocoa/Core'
s.source_files = 'Source/*.{h,m,swift}'
....

Some header files contains:

一些头文件包含:

#import <ReactiveCocoa/RACSignal.h>

I include it in a new project:

我将它包含在一个新项目中:

use_frameworks!
....
pod 'ReactiveCocoa'
pod 'MineLibrary', :git => 'git@.....'

But when i compile project i'm getting an error:

但是当我编译项目时出现错误:

duplicate interface definition for class 'RACStream'
duplicate interface definition for class 'RACSignal'


/Users/USER/Library/Developer/Xcode/DerivedData/Project-emcwpmbbuimotuftzijeemvngrvj/Build/Products/Debug-iphoneos/Pods/ReactiveCocoa.framework/Headers/RACStream.h:27:1: error: duplicate interface definition for class 'RACStream'

@interface RACStream : NSObject
^
/Users/USER/Workspace/Project/Pods/ReactiveCocoa/ReactiveCocoa/RACStream.h:27:12: note: previous definition is here
@interface RACStream : NSObject

How it can be solved?
P.S. I'm using cocoapods 0.36.0.rc.1

如何解决?
PS 我正在使用 cocoapods 0.36.0.rc.1

采纳答案by JRG-Developer

Have you tried updating to the latest release of CocoaPods? I noticed you mentioned you're using an outdated release candidate, which is possibly at fault here.

您是否尝试过更新到最新版本的 CocoaPods?我注意到您提到您使用的是过时的候选版本,这可能是这里的错误。

In general, here's what you need to do when creating and using a CocoaPod in your app:

通常,在您的应用程序中创建和使用 CocoaPod 时,您需要执行以下操作:

1) In your CocoaPod, declare all of your dependencies in the pod spec, using s.dependencyfor each

1) 在你的 CocoaPod 中,在 pod 规范中声明你的所有依赖项,使用s.dependencyfor each

2) In your app, use CocoaPods to manage all of of your app dependencies. That is, don'tmanually drag-and-drop libraries into your app. If you do, you risk creating duplicate classes with the ones that you drag-and-drop include.

2) 在您的应用程序中,使用 CocoaPods 来管理您的所有应用程序依赖项。也就是说,不要手动将库拖放到您的应用程序中。如果这样做,您可能会使用拖放包含的类创建重复的类。

3) In both your app and CocoaPod, depend on as flexible versions as you can. In general, you should at least allow for minor version updates, e.g. pod 'PodName', '~> 1.0.0'.

3) 在您的应用程序和 CocoaPod 中,尽可能依赖灵活的版本。通常,您至少应该允许次要版本更新,例如pod 'PodName', '~> 1.0.0'.

4) In your app's pod file, specify a target for your app and your unit test target, e.g.

4) 在您的应用程序的 pod 文件中,为您的应用程序和单元测试目标指定一个目标,例如

target "MyApp" do
  # App pods...
end

target "MyAppTests", :exclusive => true do
  # Test pods...
end

If you have more than two targets, specify a target for each. Or, at the very least, specify a different target for unit tests, which will get the app injected into it.

如果您有两个以上的目标,请为每个目标指定一个目标。或者,至少,为单元测试指定一个不同的目标,这将使应用程序注入其中。

回答by Jangles

I was having this issue a while back, somebody imported a cocoapod header incorrectly. Make sure you use bracket notation, E.G. rather than: #import "theUsefulClass.h"you should be using: #import <thePod/theUsefulClass.h>

不久前我遇到了这个问题,有人错误地导入了 cocoapod 标头。确保您使用括号表示法,EG 而不是: #import "theUsefulClass.h"您应该使用: #import <thePod/theUsefulClass.h>

回答by Tommie C.

In Xcode, you can check the Symbol Navigator (Cmd-3) to see where the symbol is defined twice. This will allow you to make a decision about what to do. In my case, I found two symbols with the same name from two different libraries. Maybe one of these could have a prefix added to the symbol name to disambiguate the conflict.

在 Xcode 中,您可以检查符号导航器 (Cmd-3) 以查看符号在哪里定义了两次。这将使您能够决定要做什么。就我而言,我从两个不同的库中发现了两个同名的符号。也许其中之一可以在符号名称中添加前缀以消除冲突。