programing

Xcode 프로젝트를 위해 포드 파일에 여러 대상을 지정하려면 어떻게 해야 합니까?

muds 2023. 5. 11. 21:56
반응형

Xcode 프로젝트를 위해 포드 파일에 여러 대상을 지정하려면 어떻게 해야 합니까?

저는 Xcode 4 프로젝트와 함께 CocoPods를 사용하고 있으며, 제 프로젝트에는 세 가지 목표가 있습니다(기본값, Lite 버전 구축용, 데모 버전 구축용).모든 대상이 동일한 라이브러리를 사용하지만 코코아 포드는 기본 대상에 정적 라이브러리 및 검색 경로만 추가합니다.내 포드 파일은 다음과 같습니다.

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'

제가 이 작업을 수행할 수 있는 유일한 방법은 모든 포드를 다시 나열하여 각 대상을 개별적으로 지정하는 것이었습니다.

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를 사용하는 대신 구문이 변경되었습니다.link_with다음과 같은 작업을 수행합니다.

# Note; name needs to be all lower-case.
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

오래된 답변 이전 코코아 포드 1.0:

네, 더 좋은 방법이 있습니다!당신이 할 수 있는 곳을 확인하세요.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'

abstract_target을 사용한 접근:

아래의 예에서,'ShowsiOS','ShowsTV'그리고.'ShowsTests'목표물들은 그들만의 개별적인 포드를 가지고 있습니다, 그리고.ShowsKit모두 더미 대상의 자식이기 때문에 상속됨'Shows'.

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

  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end

  # Our tests target has its own copy
  # of our testing frameworks
  # (beside inheriting ShowsKit pod).

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

더 나은 해결책은

# Podfile

platform :ios, '8.0'

use_frameworks!

# Available pods

def available_pods
    pod 'AFNetworking', '1.1.0'
    pod 'Reachability', '~> 3.1.0'
end

target 'demo' do
  available_pods
end

target 'demoTests' do
    available_pods
end

참조: http://natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/

여러 대상이 동일한 포드를 공유하도록 하려면 abstract_target을 사용합니다.

# 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

아니면 그냥

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

출처: https://guides.cocoapods.org/using/the-podfile.html

가장 쉬운 방법은 추상적인 대상을 사용하는 것입니다. 여기서 지정된 각 포드는 모든 대상과 연결됩니다.

abstract_target 'someNameForAbstractTarget' do
  pod 'podThatIsForAllTargets'
end

target 'realTarget' do
  pod 'podThatIsOnlyForThisTarget'
end

언급URL : https://stackoverflow.com/questions/14906534/how-do-i-specify-multiple-targets-in-my-podfile-for-my-xcode-project

반응형