Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to share the some pods in two target by podfile

Tags:

xcodeproj 'Demo.xcodeproj'

platform :ios, "6.0"

target "Demo" do
    pod 'Demo-A', '3.1.1'
    pod 'Demo-B', '1.0'
    pod 'Demo-C', '~> 1.9.0'
    pod 'Demo-D', '~> 1.1'

    pod 'AA', '0.0.1'
    pod 'BB', '0.0.1'
    pod 'CC', '0.0.1'
    pod 'DD', '0.0.1'
    pod 'EE', '0.0.1'
    pod 'FF', '0.0.1'
    pod 'GG', '0.0.1'
end

target "DemoTests" do
    pod 'DemoTests-X', '3.1.1'
    pod 'DemoTests-Y', '0.4.0'
    pod 'DemoTests-Z', '4.1.1'

    pod 'AA', '0.0.1'
    pod 'BB', '0.0.1'
    pod 'CC', '0.0.1'
    pod 'DD', '0.0.1'
    pod 'EE', '0.0.1'
    pod 'FF', '0.0.1'
    pod 'GG', '0.0.1'
end

target "DemoWidget" do
    pod 'DemoWidget-1', '3.1.1'
    pod 'DemoWidget-2', '0.4.0'
    pod 'DemoWidget-3', '4.1.1'
end

this is my podfile . as u can see.

pod 'AA', '0.0.1'
pod 'BB', '0.0.1'
pod 'CC', '0.0.1'
pod 'DD', '0.0.1'
pod 'EE', '0.0.1'
pod 'FF', '0.0.1'
pod 'GG', '0.0.1'

this code is appear twice. DemoTests is test target for Demo target.while i write test file and improt the source file in Demo target.it will dependence some file in pods which in Demo target,but not in DemoTests target. so i write this Podfile code twice for dependence. but,it's ugly! my colleagues and i have to maintain two sets of such code.and my Podfile will be Bloated! i want to maintain this code once! how to do it~ I love cocoapods! i believe it will solve my problem ~ waiting for u answer~~~~

like image 655
zixun Avatar asked Mar 23 '15 07:03

zixun


People also ask

What does platform mean in Podfile?

It specifies the minimum OS version you are going to support for the pod project. If your applications project's deployment target is less than the pod project mentioned iOS version, you will get a warning if there any any APIs which are deprecated in the supported OS versions in the main project.


2 Answers

You can use it like this to reduce your length of podfile and would also be able to maintain code once!!!

xcodeproj 'Demo.xcodeproj'

platform :ios, "6.0"

def common_pods_for_target
    pod 'AA', '0.0.1'
    pod 'BB', '0.0.1'
    pod 'CC', '0.0.1'
    pod 'DD', '0.0.1'
    pod 'EE', '0.0.1'
    pod 'FF', '0.0.1'
    pod 'GG', '0.0.1'
end

target "Demo" do
    pod 'Demo-A', '3.1.1'
    pod 'Demo-B', '1.0'
    pod 'Demo-C', '~> 1.9.0'
    pod 'Demo-D', '~> 1.1'
    common_pods_for_target
end

target "DemoTests" do
    pod 'DemoTests-X', '3.1.1'
    pod 'DemoTests-Y', '0.4.0'
    pod 'DemoTests-Z', '4.1.1'
    common_pods_for_target
end

target "DemoWidget" do
    pod 'DemoWidget-1', '3.1.1'
    pod 'DemoWidget-2', '0.4.0'
    pod 'DemoWidget-3', '4.1.1'
end

Just define all your common pods in a variable and use it in the targets you want.

like image 81
Dheeraj Singh Avatar answered Oct 31 '22 00:10

Dheeraj Singh


CocoaPods now recommends using an abstract_target if you want multiple targets to share the same pods. Notice how the actual targets are nested under the new abstract one.

# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'
  pod 'Fabric'

  # Has its own copy of ShowsKit + ShowWebAuth
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end
end
like image 37
Joe Masilotti Avatar answered Oct 31 '22 00:10

Joe Masilotti