使用 Ruby XcodeProj 创建 Xcode 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15872684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create Xcode Project with Ruby XcodeProj
提问by btype
I had this idea of making a command line utility similar to the rails setup application. It should automatically create a Xcode project, setup unit test, setup Frank, install most used Cocoapods and setup a project structure.
我有制作一个类似于 rails setup 应用程序的命令行实用程序的想法。它应该自动创建一个 Xcode 项目,设置单元测试,设置 Frank,安装最常用的 Cocoapods 并设置项目结构。
There is no such thing at the moment and I would really like to have it and open source it. I struggled around the other questions here yesterday but found nothing up to date.
目前没有这样的东西,我真的很想拥有它并开源它。昨天我在这里挣扎了其他问题,但没有发现任何最新信息。
I came up with the idea using XcodeProjwhich is used by CocoaPods to generate a project containing the Pods. So it should not be impossible to do. I also found XcodeProjectbut this seems to be read-only.
我想出了使用XcodeProj的想法,CocoaPods使用它来生成包含 Pod 的项目。所以这应该不是不可能做到的。我还找到了XcodeProject但这似乎是只读的。
Can someone (maybe of the Cocoapods developers) give me a hint where to start, because the Xcodeproj gem is very undocumented.
有人(可能是 Cocoapods 开发人员)能给我一个从哪里开始的提示,因为 Xcodeproj gem 非常没有记录。
回答by Fabio
To the best place to start to use Xcodeproj is the Xcodeproj::Project
class.
开始使用 Xcodeproj 的最佳位置是Xcodeproj::Project
类。
Once you open a project the Xcodeproj API allows to edit all the known attributes easily. However you need to keep in mind the following concepts:
打开项目后,Xcodeproj API 允许轻松编辑所有已知属性。但是,您需要记住以下概念:
- If an attribute is a String you can edit it directly.
- If an attribute stores an object it is necessary to ask the project to create a newone so it is has the chance to assign an UUID.
- If you are editing an attribute which stores a list of objects it is safe only to use the method exposed by the ObjectList.
- Xcodeproj performs type checking when you assign values to attributes.
- 如果属性是字符串,您可以直接编辑它。
- 如果一个属性存储一个对象,则有必要要求项目创建一个新对象,以便它有机会分配一个 UUID。
- 如果您正在编辑存储对象列表的属性,则仅使用ObjectList公开的方法是安全的。
- 当您为属性赋值时,Xcodeproj 会执行类型检查。
The following lightly tested code should help to get you started by creating a new project named Test with a target named App for a deployment target of iOS 6.0 that adds Class.h and Class.m file to the project, ensuring Class.m is included in the target.
以下经过简单测试的代码应该有助于帮助您开始创建一个名为 Test 的新项目,目标名为 App,用于 iOS 6.0 的部署目标,将 Class.h 和 Class.m 文件添加到项目中,确保包含 Class.m在目标中。
require 'xcodeproj'
proj = Xcodeproj::Project.new
app_target = proj.new_target(:application, 'App', :ios, '6.0')
header_ref = proj.main_group.new_file('./Class.h')
implm_ref = proj.main_group.new_file('./Class.m')
app_target.add_file_references([implm_ref])
proj.save_as('Test.xcodeproj')
Please let us know, opening an issue, which parts of the documentation you find confusing. For more karma use a pull request.
请让我们知道,打开一个问题,您觉得文档的哪些部分令人困惑。对于更多业力,请使用拉取请求。