The Xcodeproj Ruby gem is an excellent tool to create and update Xcode projects for iOS and Mac apps. I wanted to use it on a command line tool I was building recently. This tool is being used to help improve the productivity of iOS developers. The Xcodeproj gem is a perfect example of a productivity improvement tool. That is what we should all be striving to create.
However, I was not able to find any good documentation. Finally, I had to read the spec tests in their source code to determine how to properly use it.
Add New File to Project
I wanted to provide an example of how to use this gem in your Ruby code. This example will show you how to update your Xcode project by adding a new file.
# Open the existing Xcode project project_file = product_name + '.xcodeproj' project = Xcodeproj::Project.new(project_file) # Add a file to the project in the main group file_name = 'Message.m' group_name = product_name file = project.new_file(file_name, group_name) # Add the file to the main target main_target = project.targets.first main_target.add_file_references([file]) # Save the project file project.save_as(project_file)
The example above opens exising Xcode project, adds a file to the project in the main group, adds the file to the main target, and saves the Xcode project file.
I would like to thank the amazing team at CocoaPods who created the Xcodeproj gem and helped us improve our productivity. This is also the same team that created the CocoaPods Ruby gem that we are also using.
This gem is another building block in our productivity improvement technologies for iOS developers. I feel that our mobile software development community has not done enough lately to improve the productivity of our developers. It still takes a long time to create high-quality mobile apps. As a community we need to continuously improve our productivity tools to rapidly speed up the development of mobile apps. This is the responsibility of the talented software engineers in the mobile industry.