如何在我的 Podfile 中为我的 Xcode 项目指定多个目标和项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20853638/
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
How do I specify multiple targets and projects in my podfile for my Xcode project?
提问by allenlinli
I have one workspace that contains 3 projects (Project1, Project2), which Project1 contains 2 targets (Target1, Target2), and Project2 contains 1 target (target3). And the directory structure looks like the diagram below.
我有一个包含 3 个项目(Project1、Project2)的工作区,其中 Project1 包含 2 个目标(Target1、Target2),Project2 包含 1 个目标(target3)。目录结构如下图所示。
How do I setup Podfile so every target has the pod 'RestKit'?
如何设置 Podfile 以便每个目标都有 Pod 'RestKit'?
I don't know what 'link_with' and Please write me the podfile and explain to me, thank you a lot.
我不知道什么是“link_with”,请给我写 podfile 并向我解释,非常感谢。
MyApp
|
+-- MyApp.xcworkspace
|
+-- Project1
| |
| +-- Target1.xcodeproj
| +-- (source code)
| |
| +-- Target2
| +-- (source code)
|
|
+-- Project2
| |
| +-- Target3.xcodeproj
| +-- (source code)
|
+-- Target3
|
+-- (source code)
回答by vampirewalk
This Podfile hasn't been verified, but may show you a basic idea of multiple projects and targets setting.
此 Podfile 尚未经过验证,但可能会向您展示多个项目和目标设置的基本概念。
workspace 'MyApp'
xcodeproj 'Project1/Project1.xcodeproj'
xcodeproj 'Project2/Project2.xcodeproj'
target :Target1 do
platform :ios, '6.0'
pod 'RestKit'
xcodeproj 'Project1/Project1.xcodeproj'
end
target :Target2 do
platform :ios, '6.0'
pod 'RestKit'
xcodeproj 'Project2/Project2.xcodeproj'
end
target :Target3 do
platform :ios, '6.0'
pod 'RestKit'
xcodeproj 'Project1/Project1.xcodeproj'
end
The first line specifies your workspace. Check http://guides.cocoapods.org/syntax/podfile.html#workspace
第一行指定您的工作区。检查http://guides.cocoapods.org/syntax/podfile.html#workspace
Second line and third line specify your xcodeprojs. http://guides.cocoapods.org/syntax/podfile.html#xcodeproj
第二行和第三行指定您的 xcodeprojs。 http://guides.cocoapods.org/syntax/podfile.html#xcodeproj
And then, specify pod dependencies for targets one by one.
然后,一一指定目标的 pod 依赖项。
回答by dB.
Here's a working example from https://github.com/dblock/ARASCIISwizzle:
这是来自https://github.com/dblock/ARASCIISwizzle的一个工作示例:
workspace 'ARASCIISwizzle'
pod 'ARASCIISwizzle', :path => 'ARASCIISwizzle.podspec'
xcodeproj 'Demo.xcodeproj'
target 'Demo' do
pod 'FLKAutoLayout', '~> 0.1.1'
xcodeproj 'Demo.xcodeproj'
end
target 'IntegrationTests' do
pod 'Specta', '~> 0.2.1'
pod 'Expecta', '~> 0.2.3'
pod 'FBSnapshotTestCase', :head
pod 'EXPMatchers+FBSnapshotTest', :head
xcodeproj 'Demo.xcodeproj'
end
target 'Tests' do
pod 'Specta', '~> 0.2.1'
pod 'Expecta', '~> 0.2.3'
pod 'FBSnapshotTestCase', :head
pod 'EXPMatchers+FBSnapshotTest', :head
pod 'OCMock', '~> 2.2.3'
xcodeproj 'Tests.xcodeproj'
end
Note the discussion in https://github.com/CocoaPods/CocoaPods/issues/1922, the CocoaPods team is reworking this DSL to be less backwards.
请注意https://github.com/CocoaPods/CocoaPods/issues/1922 中的讨论,CocoaPods 团队正在重新设计此 DSL,以减少落后。
回答by den
In the current version of CocoaPods xcodeproj
is substituted with project
.
在当前版本的 CocoaPodsxcodeproj
中替换为project
.
Given the project structure:
鉴于项目结构:
MyApp
├- MyApp.xcworkspace
├- Project1
├- Target1.xcodeproj
├- Target2.xcodeproj
├- Project2
├- Target3.xcodeproj
Podfile
will look like this:
Podfile
看起来像这样:
workspace 'MyApp'
project 'Project1/Target1.xcodeproj'
project 'Project1/Target2.xcodeproj'
project 'Project2/Target3.xcodeproj'
target 'Target1' do
project 'Project1/Target1.xcodeproj'
pod 'RestKit'
end
target 'Target2' do
project 'Project1/Target2.xcodeproj'
pod 'RestKit'
end
target 'Target3' do
project 'Project2/Target3.xcodeproj'
pod 'RestKit'
end