Podfile 中 link_with 的真正含义是什么?
What is the real meaning of the link_with in the Podfile?
我的问题是,我不知道在我的 Podfile 中使用 link_with
之后到底发生了什么,所以我不知道何时何地使用 it.I 已阅读 guide 但描述是为了简要了解 link_with
.
的含义
经过我的测试,我知道如果我在我的 Podfile 中使用没有 target
的 link_with
,默认的 Pods 库 libPods.a 将链接到 link_with
引用的目标。但是如果 Podfile 中有 target
,则 link_with
看起来不再有用了。
除此之外,官方指南没有提到link_with
写在哪里,所以当我在target
块中看到link_with 'Dummy'
时,我很困惑。
谁能解释一下何时何地写link_with
以及使用link_with 'Dummy'
的原因?(我只知道它是用来解决库中重复符号的)
正如document所说,与一个目标项目一起使用没有意义:
If no explicit target is specified, then the Pods target will be
linked with the first target in your project. So if you only have one
target you do not need to specify the target to link with.
例如我有一个多目标应用程序,这里是我的 Podfile 的前几行:
platform :ios, '9.3'
workspace 'MyApplication'
link_with 'target1', 'target2', 'target3', 'target4'
pod 'AFNetworking', '~> 2.5.4'
pod 'Reachability'
pod 'SDWebImage', '~> 3.7.2'
pod 'CocoaLumberjack'
等等
在这里使用很有意义,因为如果你不使用 "target2, target3 and target4",那么在构建它时会出错。这就是我们使用它的原因。
或者,您可以为每个目标指定 pods,并为公共 pods 添加共享 pods,如下所示:
platform :ios, '9.3'
workspace 'MyApplication'
def shared_pods
pod 'AFNetworking', '~> 2.5.4'
pod 'SDWebImage', '~> 3.7.2'
pod 'CocoaLumberjack', '~> 2.0.0'
end
target :target1, :exclusive => true do
shared_pods
end
target :target2, :exclusive => true do
shared_pods
pod 'Mantle'
end
target :target3, :exclusive => true do
shared_pods
pod 'MBProgressHUD', '~> 0.9.1'
end
target :target4, :exclusive => true do
shared_pods
end
@Yujie Ren 一切都清楚了吗?
此外,检查 here 的 :exclusive => true do
含义。
问题 1:link_with 对比目标:
这里的关键词是:
If no explicit target is specified...
target:
和link_with
是互斥的:使用一个或另一个
- 如果所有您的目标使用相同的Pods依赖项,则使用
link_with
作为快捷方式。
- 使用
target:
为每个目标指定单独的Pods 依赖项。 注意: link_with
关键字在定义了1个或多个target:
时被忽略; target:
优先。
问题 2:link_with'Dummy'
Building a static library with cocoapods
这是防止 Pod 包含在静态库中的变通方法,因此该 Pod 不属于该库的一部分。通过将名为 'Dummy' 的实际目标添加到您的主要静态库项目,并指定您的 Pods 应该链接到 'Dummy',您可以欺骗 Cocoapods 获取所需的 Pods ,但不要将它们包含在您的静态库中。此处相关 post:Building a static library with cocoapods.
我的问题是,我不知道在我的 Podfile 中使用 link_with
之后到底发生了什么,所以我不知道何时何地使用 it.I 已阅读 guide 但描述是为了简要了解 link_with
.
经过我的测试,我知道如果我在我的 Podfile 中使用没有 target
的 link_with
,默认的 Pods 库 libPods.a 将链接到 link_with
引用的目标。但是如果 Podfile 中有 target
,则 link_with
看起来不再有用了。
除此之外,官方指南没有提到link_with
写在哪里,所以当我在target
块中看到link_with 'Dummy'
时,我很困惑。
谁能解释一下何时何地写link_with
以及使用link_with 'Dummy'
的原因?(我只知道它是用来解决库中重复符号的)
正如document所说,与一个目标项目一起使用没有意义:
If no explicit target is specified, then the Pods target will be linked with the first target in your project. So if you only have one target you do not need to specify the target to link with.
例如我有一个多目标应用程序,这里是我的 Podfile 的前几行:
platform :ios, '9.3'
workspace 'MyApplication'
link_with 'target1', 'target2', 'target3', 'target4'
pod 'AFNetworking', '~> 2.5.4'
pod 'Reachability'
pod 'SDWebImage', '~> 3.7.2'
pod 'CocoaLumberjack'
等等
在这里使用很有意义,因为如果你不使用 "target2, target3 and target4",那么在构建它时会出错。这就是我们使用它的原因。
或者,您可以为每个目标指定 pods,并为公共 pods 添加共享 pods,如下所示:
platform :ios, '9.3'
workspace 'MyApplication'
def shared_pods
pod 'AFNetworking', '~> 2.5.4'
pod 'SDWebImage', '~> 3.7.2'
pod 'CocoaLumberjack', '~> 2.0.0'
end
target :target1, :exclusive => true do
shared_pods
end
target :target2, :exclusive => true do
shared_pods
pod 'Mantle'
end
target :target3, :exclusive => true do
shared_pods
pod 'MBProgressHUD', '~> 0.9.1'
end
target :target4, :exclusive => true do
shared_pods
end
@Yujie Ren 一切都清楚了吗?
此外,检查 here 的 :exclusive => true do
含义。
问题 1:link_with 对比目标:
这里的关键词是:
If no explicit target is specified...
target:
和link_with
是互斥的:使用一个或另一个
- 如果所有您的目标使用相同的Pods依赖项,则使用
link_with
作为快捷方式。 - 使用
target:
为每个目标指定单独的Pods 依赖项。 注意:link_with
关键字在定义了1个或多个target:
时被忽略;target:
优先。
问题 2:link_with'Dummy'
Building a static library with cocoapods
这是防止 Pod 包含在静态库中的变通方法,因此该 Pod 不属于该库的一部分。通过将名为 'Dummy' 的实际目标添加到您的主要静态库项目,并指定您的 Pods 应该链接到 'Dummy',您可以欺骗 Cocoapods 获取所需的 Pods ,但不要将它们包含在您的静态库中。此处相关 post:Building a static library with cocoapods.