随着Cocoapods v1.5的引入允许Swift静态库,我一直在尝试将我的私有pod(最初只是Objective-C)转换为包括Swift。我已经做到了,但是对于吊舱中的所有类别,我都留下了警告“类别的重复定义”。可能是我做的很愚蠢,因为模块化标头对我来说是新的。
我有两个私有容器,一个是用于开发的共享库,另一个是用于测试的共享库。为简便起见,我在下面的Podfile中删除了一些目标和pod引用。
我注意到,警告的数量可能会上升或下降,这取决于我如何从应用程序的私有pod中导入代码。传统上我只使用过:#import“ Class.h”。现在,当我尝试使用@import;时,警告上升了。有一次,当我使用#import时,它们崩溃了。但并非每次都如此。
如果我使用#import而不是#import“ SomeClass.h”, 还会出现76条警告。
我在做什么错了?
我发现的是,如果仅通过.m文件引用类别头文件,则警告消失。
source 'https://privatepod.url.com/git/my_podspec'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_modular_headers!
inhibit_all_warnings!
def test_pods
pod 'M13ProgressSuite', '~> 1.2', :inhibit_warnings => true
pod 'AimpTestKit', :path => '../aimptestkit', :inhibit_warnings => false
pod 'Quick', :inhibit_warnings => true
pod 'Nimble', :inhibit_warnings => true
end
def common_pods
pod 'M13ProgressSuite', '~> 1.2', :inhibit_warnings => true
pod 'HockeySDK', :subspecs => ['AllFeaturesLib'], :inhibit_warnings => true
pod 'AimpKit', :path => '../aimpkit', :inhibit_warnings => false
end
target ‘free_app’ do
common_pods
target 'free_app Tests' do
inherit! :search_paths
test_pods
end
end
target ‘paid_app’ do
common_pods
target 'PaidAppTests' do
inherit! :search_paths
test_pods
end
end
target 'LogicTests' do
#no host app
inherit! :search_paths
common_pods
test_pods
end
这是共享库的podspec(为简便起见,我删除了一些多余的内容):
{
"name": "AimpKit",
"version": "3.0.1",
"summary": "AimpKit library",
"static_framework": true,
"platforms": {
"ios": "9.0"
},
"source": {
"git": "https://privatepod.url.com/git/my_podspec",
"branch": "master"
},
"source_files": "aimpkit/**/*.{h,m,swift}",
"resources": "resources/**/*.{xib,xcassets,storyboard,bundle,png,mp4}",
"requires_arc": [
"aimpkit/arc/**/*.{h,m,swift}"
],
"frameworks": [
"CFNetwork",
"Foundation",
],
"dependencies": {
"HockeySDK/AllFeaturesLib": [
],
}
}
答案 0 :(得分:0)
解决此问题的关键是确保在类标题中不引用类别标题。因此,一个类没有在其.h文件中导入类别标头。将所有这些类别头文件导入(重要工作)移动到每个类文件的.m文件即可解决此问题。
还存在一个问题,即在类标题中声明的命名类别也被声明为重复的。大概是因为该类头被其他头调用,并且该类中的类别定义被多次看到。解决方案是从类别定义中删除名称。
所有类别标头文件都在由条件语句包围的框架标头(例如)中引用,因此仅被解析一次(例如#ifndef AimpKit_h #define AimpKit_h #endif)。