Nilesh Agrawal Nilesh Agrawal - 1 year ago 121
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

file. I searched about the
file but was not able to get much information about it. Can anyone let me know what is use of the
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')

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 hello HelloWorld manisha-rules_camdo.plist
is the script I wrote,
is the existing cordova project and
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 hello HelloWorld manisha-rules_camdo.plist

is the name of cordova project and
name of iOS target.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download