Create Xcode Project with Ruby XcodeProj

夙愿已清 提交于 2019-12-03 10:17:57

问题


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.

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.

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


回答1:


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

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:

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

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.



来源:https://stackoverflow.com/questions/15872684/create-xcode-project-with-ruby-xcodeproj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!