【问题标题】:Targets within a target in a PodfilePodfile 中目标内的目标
【发布时间】:2017-08-03 15:51:51
【问题描述】:

我正在尝试将 Google 移动广告 SKD 安装到我的 Xcode 项目中。我安装了 Cocoapods,然后在我的项目中初始化了一个 Podfile:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'

target 'Cubical' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Cubical

  target 'CubicalTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'CubicalUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

但是,我不明白为什么我的主要项目(Cubical)中有目标。我从来没有真正使用过 CubicalTests 或 CubicalUITests,因为我真的不需要测试我的 UI 或任何 sn-p 代码。 我正在考虑删除这两个文件夹。

我的问题是,

1) 从我的 Xcode 项目中删除 Tests 和 UITests 文件夹有什么缺点吗?如果我这样做了,我可以直接从我的 Podfile 中删除这两个目标吗?

2) 假设我要保留这两个目标。我是否必须将吊舱添加到所有三个目标?或者这两个嵌套的目标是否继承了目标“立方”的任何豆荚

3) 我是否需要将 Google 移动广告 SDK 添加到链接框架?还是 Cocoapods 已经做到了?

我的最终 pod 应该是这样的:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'

target 'Cubical' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  pod 'Google-Mobile-Ads-SDK'

  # Pods for Cubical

  target 'CubicalTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'CubicalUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

【问题讨论】:

    标签: ios swift xcode cocoapods


    【解决方案1】:

    问题 1:

    如果您不需要执行此类测试,则删除 TestsCubicalUITests 目标和文件夹时没有问题。

    问题 2

    您可以与多个目标共享 pod,如下所示,

    def shared
    pod 'Google-Mobile-Ads-SDK'
    end
    
    target 'Target1' do
    shared
    end
    
    target 'Terget2' do
    shared
    end
    

    多个目标的全局 pod

    #Global Pod for all targets
    pod 'Google-Mobile-Ads-SDK'
    
    target 'target1' do
        pod 'Fabric' #Pod for nested Target. i.e., Google-Mobile-Ads-SDK + Fabric
    end
    
    target 'target2' do
     pod 'RadioButton'#Pod for nested Target. i.e., Google-Mobile-Ads-SDK + RadioButton
    end
    

    用于嵌套目标的 Pod:

    #Global Pod for all targets
    pod 'Google-Mobile-Ads-SDK'
    
    target 'target1' do
       pod 'RadioButton' #Available for target1 and target2
       target 'target2 copy' do 
          pod 'Fabric' #Available for target2 only
       end
    end
    

    问题 3:

    链接的框架由 cocoapods 自动完成。见here你需要使用没有cocoapods的框架来链接框架。

    【讨论】:

    • 惊人的答案,但是嵌套目标和全局目标之间有什么区别? (如果这甚至是正确的命名法,而不是 Ruby 的经验)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2023-01-19
    • 2022-07-14
    相关资源
    最近更新 更多