使用Cocoapods管理多个目标的依赖关系 [英] Manage Dependencies of Multiple Targets with Cocoapods

查看:217
本文介绍了使用Cocoapods管理多个目标的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始修改cocoapods来管理iOS项目的依赖项。
目前我正在尝试使用GHIOSUnit集成单元测试。我按照他们的所有指示进行了样本测试,这些都像魅力一样。

I just started tinkering with cocoapods to manage dependencies of my iOS Projects. Currently I am trying to integrate unit tests using GHIOSUnit. I followed all their instructions and tried their sample tests and it all worked like charm.


然而,当我开始使用我的实际项目文件进行测试时会出现问题。

However, problems start when I start using my actual project files for testing.

我正在使用AFNetworking进行客户端服务器通信以及每当我访问名为'CRLClient'的sharedClient,AFHTTPClient的包装器,它给我未定义的符号错误。

I am using AFNetworking for client server comms and whenever I access my sharedClient called 'CRLClient', a wrapper for AFHTTPClient, it gives me undefined symbols errors.

Undefined symbols for architecture armv7:
  "_OBJC_METACLASS_$_AFHTTPClient", referenced from:
      _OBJC_METACLASS_$_CRLClient in CRLClient.o
  "_OBJC_CLASS_$_AFJSONRequestOperation", referenced from:
      objc-class-ref in CRLClient.o
  "_OBJC_CLASS_$_AFHTTPClient", referenced from:
      _OBJC_CLASS_$_CRLClient in CRLClient.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

用于管理依赖项的pod文件如下所示

The pod file for managing dependencies looks like this

workspace 'Storyboards.xcworkspace'
platform :ios, '5.0'
pod 'AFNetworking', '1.1.0'
target :UnitTests, :exclusive => true do
pod 'GHUnitIOS', '0.5.6'
end

实际项目目标构建良好,并与AFNetworking完美配合。

The actual project target builds fine and works with AFNetworking perfectly.

PS我需要添加要测试的所有文件以添加到UnitTest Target。那么在构建阶段添加Target Dependency会有什么影响?

P.S. I am required to add all the files to be tested to be added to the UnitTest Target as well. Then what does adding 'Target Dependency' in build phases do?


简而言之,


  1. 如何分享不同目标之间的共同依赖关系?

  2. 如果我还要将每个文件添加到新目标,添加目标依赖项真的会做什么?


推荐答案

使用

target :UnitTests, :exclusive => true do
  pod 'GHUnitIOS', '0.5.6'
end

你说你想要链接到 UnitTests 目标的唯一库是 GHUnit 主要是说你不要想要 AFNetworking 也要链接。问题是你似乎还要将 AFHTTPClient 子类导入 UnitTests ,它找不到AFNetworking它试图链接到的组件。

You're saying that the only library you want to be linked to the UnitTests target is GHUnit mainly saying you don't want AFNetworking to be linked as well. The problem is it looks like you're also importing your AFHTTPClient subclass into UnitTests where it can't find the AFNetworking components it's trying to link to.

要解决此问题,您应该可以删除独占电话

To fix this you should be able to remove the exclusive call

target :UnitTests do
  pod 'GHUnitIOS', '0.5.6'
end

使用此功能,您只需将 GHUnit 链接到您的 UnitTests 目标,但会链接两个人的 AFNetworking 。 默认情况下,目标将包含在块外部定义的依赖项,除非给出:exclusive => true选项。 (来自此处

With this you will link GHUnit only to your UnitTests target but will link AFNetworking to both. "The target will by default include the dependencies defined outside of the block, unless the :exclusive => true option is given." (from here)

这篇关于使用Cocoapods管理多个目标的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆