首页 > 解决方案 > 如何指定哪个构建目标包含特定的 swift 包依赖项?

问题描述

使用 swift 包管理器,我的项目中包含一个 swift 包,我只希望它在测试目标和 ui 测试目标中可用。如何选择可以访问 swift 包的目标?

标签: swiftxcodeswift-package-manager

解决方案


最简单的方法是使用 cocoapods

你的 podfile 看起来像这样

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

target 'MyApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  #use_frameworks!
  #These are the main app frameworks
  pod 'Alamofire'

  # Pods for MyApp

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
    # here would be your testing frameworks
    pod 'MyTestFramework'
  end
  
  target 'MyAppUITests' do
    # Pods for testing
    # and here your UI tests framework
  end

end

推荐阅读