Library to read/write pbxproj/xcodeproj files?

Does anyone know of a library to read/write the Xcode project files .xcodeproj/.pbxproj? Any language is welcome.

Thanks in advance.

Answers


The surface syntax of an Xcode project is an "old-style plist." You can easily convert it to an XML plist with the command

plutil -convert xml1 -o - myproj.xcodeproj/project.pbxproj

Note this is not "real XML" but the Mac OS X plist structure expressed in XML syntax; it consists almost entirely of key-value pair dictionaries and arrays. Xcode will read the XML representation but convert it back to "old-style plist" when the project is opened.

The structure and relationship of the items in the plist follow the structure of the project. The UUIDs are used to cross-reference items between the project and its targets, and between the project and the user files in the project wrapper.

The 'isa' key identifies each kind of object. The PBXProject contains PBXFileReference, PBXGroup, PBXNativeTarget, and PBXBuildConfiguration objects.

The targets have PBXBuildPhase objects that contain cross-references to the file references; BuildConfigurationLists that store the build settings for the targets, and other target settings like the target type and name.

The buildConfigurationLists cross-reference buildConfigurations, which in turn contain dictionaries of buildSettings.

I'd recommend looking at the old-style plist text first, as it's much more readable and actually has inline comments to tell you what's what. Then you can use XML tools to edit or write the project files to your liking.


I ended up creating one, and it's hosted on github here:

https://github.com/jasperblues/XcodeEditor

Allows listing headers, files, adding source files, setting source file as a member of a target, adding images, creating groups, etc).

It works by manipulating the contents of the project.pbxproj file. Used in:

  • Less Painful: Automated functional testing for mobile applications. (Edit: now part of Xamarin's tools).
  • Level Helper: A RAD framework for developing 2D games on iOS & Android.
  • TextMate
  • Apportable

I just discovered this: https://github.com/alunny/node-xcode I haven't used it yet, but it looks promising for Node.js developers.


Try this one: https://github.com/sap-production/XcodeProjectJavaAPI

It can read and write any Property List file and contains a semantic model to read and manipulate Xcode Project files. The semantic model is in an early stage but can be easily extended.

It is also used heavily in the Xcode Maven plugin of SAP, which will be released this month.


CocoaPods now have a ruby library to manipulate pbxproj files:

https://github.com/CocoaPods/Xcodeproj

As well as being used by CocoaPods, this is also used by fastlane, synx, slather and no doubt many more.


You could also consider using the PlistBuddy command :

https://marcosantadev.com/manage-plist-files-plistbuddy/

http://scriptingosx.com/2016/11/editing-property-lists/


There's a nice Python package for doing this. The documentation isn't great, but the source code is pretty organized and you can find what you need.

https://github.com/kronenthaler/mod-pbxproj


For PHP (easily ported to whatever language you need), very basic write only:

function modifyPlistXCodeProject($file_path,$app_name,$bundle_identifier,$latest_version,$bundle_version)
{
    $data = file_get_contents($file_path);
    $changes = Array();
    $changes['PRODUCT_BUNDLE_IDENTIFIER'] = $bundle_identifier;
    foreach ($changes as $key => $value){
        $data = oldStylePlistReplace($data,$key,$value);
    }
    file_put_contents($file_path, $data);
}

function oldStylePlistReplace($data,$key,$value){
    $e = explode($key,$data);
    for ($i=1;$i<count($e);$i++){
        $row_i = $e[$i];
        $nextline_pos = stripos($row_i,"\n");
        $text_i = '= '.$value.';'.substr($row_i, $nextline_pos);
        $e[$i] = $text_i;
        //var_dump(substr($text_i,0,100));exit();
    }
    return implode($key,$e);
}

Need Your Help

How to achieve this functionality using Generics?

c# oop generics design-patterns dry

I am not experienced in using .Net generics. I am designing a software system for and Investment Holding Company in .Net 4.0. The company has Retail business and IntellectualRights business. BookS...