XcodeGen - A better way to manage Xcode Projects


The problem

  • .xcodeproj files suck
  • They aren’t human readable
  • When merge conflicts do occur this makes them pretty impossible to resolve

The Current “Solution”

Adding this line to your .gitAttributes

*.pbxproj merge=union

This attribute tells git that whenever there is a merge conflict with any .pbxproj file then merge automatically and take both sides.

Nine times out of ten this will work fine. However when it dosen’t things go south real quickly.

Depending on the size of your project you can end up with hundreds of seemingly insolvable conflicts where blocks of code end up where they shouldn’t. If you have ever experienced this you know it can quickly become a nightmare.

Welcome XcodeGen

After searching for a solution I came across XcodeGen.

XcodeGen is a command line tool that generates your Xcode project using your folder structure and a simple project spec.

With XcodeGen you create Project Specs which can either be in JSON or YML. These specs contain all the information to generate a project. Targets, Schemes, Settings, Dependencies. You name it, it’s covered.

A basic application Spec can be declared in just a few lines:

After creating the Spec you simply run:

xcodegen

And the project is generated instantly!

The ProjectSpec is quite exhaustive and covers almost every edge case in regards to settings and configurations.

I would recommend any team to try out XcodeGen, as although the inital setup of creating the Specs by copying the existing settings from Xcode can seem tedius. The time and hassle saved in the future is more than worth it.

Thanks for reading!