如何以编程方式将构建文件添加到 Xcode4?
我一直在尝试弄清楚如何以编程方式将文件添加到 Xcode4 项目中,似乎 AppleScript 是可行的方法,但是我遇到了“缺失值”错误。
这是我得到的代码:
tell application "Xcode"
set theProject to first project
set theTarget to first target of theProject
set theBuildPhase to compile sources phase of theTarget
tell first group of theProject
set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
add theFileRef to theProject
end tell
--tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell
我也尝试了注释行而不是添加命令,但这也不起作用(我得到“缺失值”)。
“添加”错误是:
error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"
“创建新引用”确实将文件添加到 Xcode 中的文件列表中,但我还需要将其添加到项目目标中,以便我可以从 Xcode 将操作和出口添加到文件中无需首先选中复选框即可将其添加到“目标成员资格”。
I've been trying to figure out how to programmatically add files to an Xcode4 project and it seemed like AppleScript would be the way to go, however I'm running into "missing value" errors.
Here's the code I've got:
tell application "Xcode"
set theProject to first project
set theTarget to first target of theProject
set theBuildPhase to compile sources phase of theTarget
tell first group of theProject
set theFileRef to make new file reference with properties {full path:"/Users/jeff/Projects/XcodeTest/XcodeTest/MyViewController.h", name:"MyViewController.h", path:"XcodeTest/MyViewController.h", path type:group relative}
add theFileRef to theProject
end tell
--tell theBuildPhase to make new build file with properties {build phase:theBuildPhase, name:"MyViewController.h", file reference:theFileRef, target:theTarget, project:theProject}
end tell
I've tried the commented-out line instead of the add-command as well, but that doesn't work either (I get "missing value").
The 'add' error is:
error "Xcode got an error: file reference id \"251AD3431432472E006E300F\" of Xcode 3 group id \"251AD32C14324645006E300F\" of project \"XcodeTest\" of workspace document \"XcodeTest.xcodeproj/project.xcworkspace\" doesn’t understand the add message." number -1708 from file reference id "251AD3431432472E006E300F" of Xcode 3 group id "251AD32C14324645006E300F" of project "XcodeTest" of workspace document "XcodeTest.xcodeproj/project.xcworkspace"
The "make new reference" does add the file to the list of files in Xcode, but I also need it to be added to the project target so that I can add actions and outlets to the file from Xcode w/o having to first check the checkbox to add it to the "target membership".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终将这个问题发送给 xcode 开发人员列表上的开发人员,而我得到的答复实际上是“你不能”。
I ended up sending this question to the devs on the xcode developer list and the response I got was effectively "you can't".
这在 Xcode4 中似乎完全被破坏了,但我见过一个项目可以做到这一点。我认为他们正在做的是直接解析和修改“project.pbxproj”文件。 (这个文件隐藏在 xcodeproj 包中)
该文件是一个 GUID 汤,但是一旦你查看它一段时间,似乎可以安全地修改它,特别是如果你只是添加东西的话。
编辑:
找到了可能有帮助的 stackoverflow 答案。
编写 XCode 构建阶段脚本的教程或指南
This appears to be completely broken in Xcode4, but I've seen a project that does it. I think what they are doing is parsing and modifying the "project.pbxproj" file directly. (this file is hidden inside the xcodeproj bundle)
The file is a GUID soup, but once you look at it for a while it seems possible to safely modify it, especially if you are only adding stuff.
Edit:
Found this stackoverflow answer that might help.
Tutorial or Guide for Scripting XCode Build Phases
可以添加一个记录很少的用户定义的构建设置。可以从编译中排除和包含文件
转到目标的“构建设置”>“点击+按钮>添加用户定义的设置
键是
INCLUDED_SOURCE_FILE_NAMES
或EXCLUDED_SOURCE_FILE_NAMES
该值是空格分隔的文件路径列表
请参阅参考:
http://lists.apple.com/archives/xcode-users /2009/Jun/msg00153.html
There is a poorly documented user defined build setting that can be added. Files can be both excluded and included from compilation
Go to your target's Build Settings > Tap the + button > Add User-Defined Setting
The key is either
INCLUDED_SOURCE_FILE_NAMES
orEXCLUDED_SOURCE_FILE_NAMES
The value is a space separated list of file paths
See reference:
http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html