使用Ruby XcodeProj创建Xcode项目 [英] Create Xcode Project with Ruby XcodeProj

查看:549
本文介绍了使用Ruby XcodeProj创建Xcode项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的想法是制作一个类似于rails setup应用程序的命令行实用程序。
它应该自动创建一个Xcode项目,设置单元测试,设置Frank,安装最常用的Cocoapods并设置项目结构。

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.

现在,我真的很想拥有它并开源。
我昨天在这里围绕其他问题苦苦挣扎,但至今没有发现任何问题。

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.

我想到了使用 XcodeProj 的想法CocoaPods使用它来生成包含Pod的项目。因此,这应该并非没有可能。我还发现了 XcodeProject ,但这似乎是只读的。

I came up with the idea using XcodeProj which is used by CocoaPods to generate a project containing the Pods. So it should not be impossible to do. I also found XcodeProject but this seems to be read-only.

有人(也许是Cocoapods开发人员)可以给我提示从哪里开始的,因为Xcodeproj gem尚无记载。

Can someone (maybe of the Cocoapods developers) give me a hint where to start, because the Xcodeproj gem is very undocumented.

推荐答案

要开始使用Xcodeproj的最佳位置是 Xcodeproj :: Project 类。

To the best place to start to use Xcodeproj is the Xcodeproj::Project class.

打开项目后,Xcodeproj API允许轻松编辑所有已知属性。但是,您需要牢记以下概念:

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:


  • 如果属性是字符串,则可以直接对其进行编辑。

  • 如果属性存储对象,则必须要求项目创建一个新一个,这样就有机会分配一个UUID。

  • 如果您正在编辑存储对象列表的属性,则仅使用 ObjectList

  • 在为属性分配值时,Xcodeproj会执行类型检查。

  • 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 new one 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.

以下经过简单测试的代码应该可以帮助您入门:创建一个名为Test的新项目,并为iOS 6.0的部署目标添加一个名为App的目标,该目标添加了Class.h和Class.m文件

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.

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.

这篇关于使用Ruby XcodeProj创建Xcode项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆