ios - Cocoapods,以通用方式为所有目标添加依赖

标签 ios swift cocoapods dependency-management swift-package-manager

应用有超过 20 个目标。

每次添加目标时,我都需要更新我的 podfile:

播客文件

target 'SomeNewTarget' do
    runAllPods // Block that contains all "pod ...."
end

我的问题:

是否有一种通用的方法可以将依赖项添加到所有目标? 我基本上想向除测试目标之外的所有目标添加相同的依赖项。

完整的足迹:

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

inhibit_all_warnings!

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

  # Pods for MyApp

  pod 'Swinject', '~> 2.1.0'
  pod 'SwinjectAutoregistration', '2.1.0'
  pod 'IHKeyboardAvoiding', '4.0'
  pod 'SnapKit', '3.2.0'
  pod 'Material', '~> 2.10.2'
  pod 'RxSwift', '~> 3.0'
  pod 'RxCocoa', '~> 3.0'
  pod 'PureLayout'
  pod 'Alamofire', '~> 4.5'

....更多依赖

end

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      if target.name == 'HydraAsync' || target.name == 'DKImagePickerController' || target.name == 'WhatsNew' || target.name == 'Closures' 
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.0'
        end
      end
    end
  end



target 'Target1' do
  runAllPods
end

target 'Target2' do
  runAllPods
end

target 'Target3' do
  runAllPods
end

target 'Target4' do
  runAllPods
end
...
target 'Target 20' do
  runAllPods
end

...更多目标

最佳答案

做这样的事情可能会奏效。

def common_pods
    pod 'Pod1'
    pod 'Pod2'
    pod 'Pod3'
    …
end

project = Xcodeproj::Project.open "../Project.xcodeproj"
project.targets.each do |t|
    target t.name do
        common_pods
    end
end

有关此方法的更多详细信息,请查看 Cocoapod 存储库中的此线程:

https://github.com/CocoaPods/CocoaPods/issues/5898

关于ios - Cocoapods,以通用方式为所有目标添加依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48505347/

相关文章:

ios - 为什么我无法缩放嵌入在 UIScrollView 中的 UIImageView?

ios - 无法在 iOS 5.1 中加载 MKMapView

swift - 从 parse.com 加载图像

ios - 重用 UIView 会导致应用卡住

xcode - 错误 : conditional compilation flags must be valid Swift identifiers (rather than 'DEBUG” ')

ios - 如何防止 UIAlertViewController 的 UITextField 中出现特殊字符?

iphone - 带有标题 View 的 UINavigationItem

ios - 从 nib 实例化 View 抛出错误

ios - 为什么 Xcode 在使用 CocoaPods 后不安装我的 iOS 应用程序?

ios - 所有 cocoa pod 库中的 Xcode 7.3.1 错误太突然了