Nilesh Agrawal Nilesh Agrawal - 12 days ago 6
Python Question

Add files to Xcode project through command line ? Use of project.pbxproj file in Xcode?

I was trying to add a plist file to a xcode project through command line, some of the blogs suggested to edit the

project.pbxproj
file. I searched about the
project.pbxproj
file but was not able to get much information about it. Can anyone let me know what is use of the
project.pbxproj
file in xcode? How does one add entries to it?

I am using this repo to work with it.

the script that I wrote is as follows:

import sys
import os
from mod_pbxproj import XcodeProject


def addPlistInProject(corodova_proj_name, xcode_proj_name, plist_file_name):
print "Cordova project name : " + corodova_proj_name
present_directory = os.getcwd()
path_to_xcode_proj = present_directory + '/' + corodova_proj_name + '/platforms/ios/' + xcode_proj_name + '.xcodeproj/project.pbxproj'
print "Xcode Project Path : " + path_to_xcode_proj
project = XcodeProject.Load(path_to_xcode_proj)
project.get_or_create_group('new group')
project.add_file(plist_file_name)


if __name__ == "__main__":
corodova_proj_name = sys.argv[1]
xcode_proj_name = sys.argv[2]
plist_file_name = sys.argv[3]
print "Xcode Project Name = : " + xcode_proj_name
print "Plist File Path = : " + plist_file_name
addPlistInProject(corodova_proj_name, xcode_proj_name, plist_file_name)


I will be invoking the script as:

python myscript.py hello HelloWorld manisha-rules_camdo.plist


myscript.py
is the script I wrote,
hello
is the existing cordova project and
HelloWorld
is the Xcode project created by using
cordova platform add iOS
.

The command Sequence I will be following will be as follows:

cordova create hello com.example.hello HelloWorld
cordova platform add iOS
py myscript.py hello HelloWorld manisha-rules_camdo.plist


Where
hello
is the name of cordova project and
HelloWorld
name of iOS target.

Answer

There is a Ruby API from Cocoapods for editing Xcode projects. It also have an active community of developers:

https://github.com/CocoaPods/Xcodeproj