iOS 프로젝트를 진행하다 보면, 하나의 workspace 안에 여러 개의 target 혹은 project를 두고 사용을 할 수 있다.
이럴 경우, 각각의 target 혹은 project에서 별도의 podfile을 유지하는 방법도 있겠지만, 공통으로 추가되는 pod 라이브러리가 있다던지, 혹은 일괄 업데이트가 필요하다던지 하는 경우가 발생할 수 있다.
나의 경우가 딱 이 경우 두가지에 모두 해당되었는데, 의외로 간단하게 해결할 수 있었다.
먼저 예시로 다음과 같은 프로젝트가 있다고 가정하자.

예시로 만든 프로젝트에서는 Sample 이라는 메인 프로젝트가 있고, 엔터프라이즈를 위한 SampleEnterprise라는 프로젝트가 하나 더 추가되어 있다.
여기에서의 요구사항은, 마스터 워크스페이스에 속한 Podfile에서 각각의 프로젝트들로 Pod 라이브러리의 의존성을 주입해주는 것이다.
처음의 Podfile은 다음과 같이 구성되어 있다.
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! inhibit_all_warnings! target 'Sample' do pod 'Alamofire' target 'SampleTests' do inherit! :search_paths end end
이제 이 Podfile의 수정을 통해서 각각의 프로젝트에는 네트워크 라이브러리인 Alamofire를 추가해 주고, Sample에는 SnapKit을, Enterprise에는 FLEX를 따로 적용해보자.
다음과 같이 수정된 Podfile을 이용한다.
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! inhibit_all_warnings! workspace 'Sample' project 'Sample.xcodeproj' project 'SampleEnterprise/SampleEnterprise.xcodeproj' def network_libs pod 'Alamofire' end target 'Sample' do project 'Sample.xcodeproj' network_libs pod 'SnapKit' target 'SampleTests' do inherit! :search_paths end end target 'SampleEnterprise' do project 'SampleEnterprise/SampleEnterprise.xcodeproj' network_libs pod 'FLEX' target 'SampleEnterpriseTests' do inherit! :search_paths end end
Podfile은 Ruby로 작성되어 있으므로, def-end 구문을 통해 공통으로 들어가는 pod을 하나로 묶을 수 있다.
그리고 위의 Podfile에서 보이듯, 추가된 각각의 Xcode Project들에 대해서 podfile에서 target을 추가할 때 project 경로를 지정해주어야만 podfile에 대한 install 이 정상적으로 수행된다.
위 Podfile에 대한 pod install 결과는 다음과 같다.

각각의 xcconfig 파일을 열어 보면 podfile에서 지정한 대로 pod 의존성이 주입되어 있는 것을 확인할 수 있다.