ios - 通过 tuist/XcodeProj 以编程方式将文件添加到 native 目标

标签 ios swift xcodeproj

我正在使用https://github.com/tuist/XcodeProj尝试将文件添加到特定目标。基本上我想使用 Swift 通过 ruby​​ 镜像完成以下操作:

require 'xcodeproj'
source_root = '/path/to/xcodeproj'
project = Xcodeproj::Project.open(source_root)

group = project.main_group['TestProject']['TestGroup']
file = group.new_file('TestFile.swift')

target = project.targets.first
target.add_file_references([file])

project.save

到目前为止,我已成功将实际文件添加到项目中,但无法将其添加到特定目标:

let sourceRoot = Path("/path/to/xcodeproj")
let project = try XcodeProj(path: sourceRoot)

let target = project.pbxproj.targets(named: "some target name").first!
let group = project.pbxproj.groups.first!

let fileReference = try group.addFile(
  at: Path("TestFile.swift"),
  sourceTree: .group,
  sourceRoot: sourceRoot
)

try project.write(path: Path(sourceRoot))

我的问题是,如何使用上面提到的库以编程方式将添加到项目的文件引用 fileReference 添加到特定目标中?

最佳答案

尝试如下操作(另请参阅目标对象 API 了解详细信息)

try target.sourcesBuildPhase().add(file: fileReference)

关于ios - 通过 tuist/XcodeProj 以编程方式将文件添加到 native 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72320308/

相关文章:

ios - 多个信标 didRangeBeacons 委托(delegate)调用一次仅返回一个信标

php - 为移动应用程序构建的 REST API

ios - 如何在 iOS 应用程序中对 2 个不同的 Google 帐户进行 oAuth

Ruby gem Xcodeproj 在项目保存时抛出异常

ios - 使用 xcodeproj 将框架添加到 "link to binary with libraries"

iphone - 理解崩溃报告

iphone - 委托(delegate)中的 MFMailComposeViewController

ios - 即使将重复间隔设置为工作日,UILocalNotification 也会每天触发

swift - -canOpenURL : failed for URL: "about:blank" - error: "This app is not allowed to query for scheme about"

ios - 从 podspec 向 Xcode 项目添加运行脚本构建阶段