如何在我的Xcode项目的podfile中指定多个目标? [英] How do I specify multiple targets in my podfile for my Xcode project?

查看:241
本文介绍了如何在我的Xcode项目的podfile中指定多个目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 4项目中使用CocoaPods,并且我的项目有三个目标(默认情况下,一个目标用于构建lite版本,一个目标用于演示版本).所有目标都使用相同的库,但是CocoaPods仅将静态库和搜索路径添加到主要目标.我的podfile看起来像这样:

platform :ios, '5.0'

pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'

让我工作的唯一方法是使用列出的所有Pod分别指定每个目标.

platform :ios, '5.0'

target :default do  
    pod 'TestFlightSDK', '>= 1.1'
    pod 'MBProgressHUD', '0.5'
    pod 'iRate', '>= 1.6.2'
    pod 'TimesSquare', '1.0.1'
    pod 'AFNetworking', '1.1.0'
    pod 'KKPasscodeLock', '0.1.5'
    pod 'iCarousel', '1.7.4'
end

target :lite do 
    link_with 'app-lite'

    pod 'TestFlightSDK', '>= 1.1'
    pod 'MBProgressHUD', '0.5'
    pod 'iRate', '>= 1.6.2'
    pod 'TimesSquare', '1.0.1'
    pod 'AFNetworking', '1.1.0'
    pod 'KKPasscodeLock', '0.1.5'
    pod 'iCarousel', '1.7.4'
end

target :demo do 
    link_with 'app-demo'

    pod 'TestFlightSDK', '>= 1.1'
    pod 'MBProgressHUD', '0.5'
    pod 'iRate', '>= 1.6.2'
    pod 'TimesSquare', '1.0.1'
    pod 'AFNetworking', '1.1.0'
    pod 'KKPasscodeLock', '0.1.5'
    pod 'iCarousel', '1.7.4'
end

有更好的方法吗?

解决方案

CocoaPods 1.0更改了此语法.现在看起来像这样:

def shared_pods
    pod 'SSKeychain', '~> 0.1.4'
    pod 'INAppStoreWindow', :head
    pod 'AFNetworking', '1.1.0'
    pod 'Reachability', '~> 3.1.0'
    pod 'KSADNTwitterFormatter', '~> 0.1.0'
    pod 'MASShortcut', '~> 1.1'
    pod 'MagicalRecord', '2.1'
    pod 'MASPreferences', '~> 1.0'
end

target 'Sail' do
    shared_pods
end

target 'Sail-iOS' do
    shared_pods
end


过时 CocoaPods 1.0之前的版本:

是的,有更好的方法!查看 link_with ,您可以在其中执行link_with 'MyApp', 'MyOtherApp'来指定多个目标.

我将其与link_with 'App', 'App-Tests'之类的单元测试一起使用(请注意目标名称中的空格).

示例:

platform :osx, '10.8'

link_with 'Sail', 'Sail-Tests'

pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'


2017更新

您可以使用抽象目标

# Note: There are no targets called "Shows" in any of this workspace's Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'

  # The target ShowsiOS has its own copy of ShowsKit (inherited) + ShowWebAuth (added here)
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # The target ShowsTV has its own copy of ShowsKit (inherited) + ShowTVAuth (added here)
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Our tests target has its own copy of
  # our testing frameworks, and has access
  # to ShowsKit as well because it is
  # a child of the abstract target 'Shows'

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

I'm using CocoaPods with my Xcode 4 project and I have three targets for my project (the default, one for building a lite version and one for building a demo version). All the targets use the same libraries, but CocoaPods is only adding the static library and search paths to the primary target. My podfile looks like this:

platform :ios, '5.0'

pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'

The only way I was get this to work was to specify each target individually with all the the pods listed again.

platform :ios, '5.0'

target :default do  
    pod 'TestFlightSDK', '>= 1.1'
    pod 'MBProgressHUD', '0.5'
    pod 'iRate', '>= 1.6.2'
    pod 'TimesSquare', '1.0.1'
    pod 'AFNetworking', '1.1.0'
    pod 'KKPasscodeLock', '0.1.5'
    pod 'iCarousel', '1.7.4'
end

target :lite do 
    link_with 'app-lite'

    pod 'TestFlightSDK', '>= 1.1'
    pod 'MBProgressHUD', '0.5'
    pod 'iRate', '>= 1.6.2'
    pod 'TimesSquare', '1.0.1'
    pod 'AFNetworking', '1.1.0'
    pod 'KKPasscodeLock', '0.1.5'
    pod 'iCarousel', '1.7.4'
end

target :demo do 
    link_with 'app-demo'

    pod 'TestFlightSDK', '>= 1.1'
    pod 'MBProgressHUD', '0.5'
    pod 'iRate', '>= 1.6.2'
    pod 'TimesSquare', '1.0.1'
    pod 'AFNetworking', '1.1.0'
    pod 'KKPasscodeLock', '0.1.5'
    pod 'iCarousel', '1.7.4'
end

Is there a better way to do this?

解决方案

CocoaPods 1.0 has changed the syntax for this. It now looks like this:

def shared_pods
    pod 'SSKeychain', '~> 0.1.4'
    pod 'INAppStoreWindow', :head
    pod 'AFNetworking', '1.1.0'
    pod 'Reachability', '~> 3.1.0'
    pod 'KSADNTwitterFormatter', '~> 0.1.0'
    pod 'MASShortcut', '~> 1.1'
    pod 'MagicalRecord', '2.1'
    pod 'MASPreferences', '~> 1.0'
end

target 'Sail' do
    shared_pods
end

target 'Sail-iOS' do
    shared_pods
end


OUTDATED Pre CocoaPods 1.0 answer:

Yes there is a better way! Check out link_with where you can do link_with 'MyApp', 'MyOtherApp' to specify multiple targets.

I use this with unit tests like link_with 'App', 'App-Tests' (beware of spaces in target's names).

Example:

platform :osx, '10.8'

link_with 'Sail', 'Sail-Tests'

pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'


2017 update

You can use abstract_target

# Note: There are no targets called "Shows" in any of this workspace's Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'

  # The target ShowsiOS has its own copy of ShowsKit (inherited) + ShowWebAuth (added here)
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # The target ShowsTV has its own copy of ShowsKit (inherited) + ShowTVAuth (added here)
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Our tests target has its own copy of
  # our testing frameworks, and has access
  # to ShowsKit as well because it is
  # a child of the abstract target 'Shows'

  target 'ShowsTests' do
    inherit! :search_paths
    pod 'Specta'
    pod 'Expecta'
  end
end

这篇关于如何在我的Xcode项目的podfile中指定多个目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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