我在为我的项目创建CocoaPods .podspec文件时遇到了麻烦,因此该文件在由CocoaPods安装时与原始项目中的模块结构相同。
我正在构建一个包含多个框架的SDK:
MyThingSDK.xcodeproj
-> Target: Framework "Core.framework"
Builds files in MyThing/Core/*.swift
-> Target: Framework "Designer.framework"
Builds files in MyThing/Designer/*.swift
-> Target: Framework "Runner.framework"
Builds files in MyThing/Runner/*.swift
构建结束时,我有三个以每个目标命名的框架
MyThingSDK.podspec看起来像:
Pod::Spec.new do |s|
s.name = "MyThingSDK"
s.version = "0.1.1"
...
s.subspec "Core" do |spec|
spec.source_files = "MyThing/Core/**/*.{h,m,swift}"
spec.public_header_files = "MyThing/Core/*.{h}"
spec.header_dir = "Core"
end
s.subspec "Designer" do |spec|
spec.source_files = "MyThing/Designer/**/*.{h,m,swift}"
spec.public_header_files = "MyThing/Designer/*.{h}"
spec.header_dir = "Designer"
spec.dependency "MyThing/Core"
end
s.subspec "Runner" do |spec|
spec.source_files = "MyThing/Runner/**/*.{h,m,swift}"
spec.public_header_files = "MyThing/Runner/**/*.{h}"
spec.header_dir = "Runner"
spec.dependency "MyThing/Core"
end
end
当我在使用pod install的客户端项目中使用它时,我最终得到以下结构:
ClientProject.xcworkspace
ClientProject.xcproject
Pods.xproject
-> Target: Framework "MyThingSDK.framework"
Builds files from MyThing/Core/*.swift
Builds files from MyThing/Designer/*.swift
Builds files from MyThing/Runner/*.swift
Podfile这样引用SDK:
pod 'MyThingSDK', :path => '/Volumes/Dev/src/MyThingSDK'
因此,当CocoaPods创建其Pods项目时,所有源文件都进入一个框架,而不是每个子规范都具有自己的框架。这会产生重复的定义问题。假设Designer和Runner都有一个名为“客户端”的类-当它们是独立的框架时很好,但是当它们合并为一个框架时就没问题了。
如何为每个子规格保留一个框架?
答案 0 :(得分:1)
子规范的主要目的之一是启用单个框架的配置。如果需要单独的框架,则应为每个框架使用单独的podspec。