ios - Podfile中link_with的真正含义是什么?

标签 ios xcode cocoapods

我的问题是,我不知道在我的 Podfile 中使用 link_with 之后到底发生了什么,所以我不知道何时何地使用它。我已经阅读了 guide但描述是为了简要了解link_with的含义。

在我的测试之后,我知道如果我在我的 Podfile 中使用没有 targetlink_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 和 target4”,那么在构建时会出错。这就是我们使用它的原因。

或者,您可以为每个目标指定 pod,并为公共(public) pod 添加共享 pod,如下所示:

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 意思。

关于ios - Podfile中link_with的真正含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31153882/

相关文章:

ios - 如何录制音频流以将其保存在 file/swift 4.2 中

ios - 模拟 iPhone 应用程序中的选项卡

ios - #import 自动完成但随后说找不到文件

iOS ARKit 指向 anchor 的指针

javascript - 在 xcode 中哪里可以找到 tvos 的 javascript 控制台?

android - 是否可以在试飞站点上传 android apk 文件..

c++ - ' fatal error : 'wchar.h' file not found' error with the new macos 11. 3 更新

ios - 安装新 Pod 时 Pod 文件错误

ios - XCode:找不到用于-lAFNetworking的库

ios - 无法在 CocoaPods 中安装 React 子规范