Tired of xcodeproj conflict? XcodeGen save the day
Have you ever encountered conflict in .xcodeproj while working with your team? I’m sure that you have encountered it many times.
Solving this kind of conflict is not always easy, because the .xcodeproj file is not human — readable, especially if you are adding and removing lots of files, modifying your project configuration, or editing your schemes. Imagine how much time we have spend to resolve this conflict, because most of the times this conflicts are pretty impossible to resolve.
Wouldn’t it be better if you had a more reliable tool to solve this kind of problem? Here, XcodeGen comes to the rescue.
In this article, I will break down how we use XcodeGen to solve this problem in our team.
Install XcodeGen
First you must install Xcodegen. There are multiple ways to install Xcodegen. In this tutorial, we’ll be using Homebrew to install Xcodegen. There are other ways of installing XcodeGen. You can check them out in the official documentation.
brew install xcodegen
Create Project Spec
XcodeGen require file project.yml
available in project to be able to generate xcodeproj. In our project.yml
we split into multiple configuration file, use include
to add that file.
We split the configuration into 4 :
- Targets
- Settings
- Schemes
- Configs
Each file have their own responsibility for generating xcodeproj. For targets.yml
basically it’s main configuration for our apps. We set build setting, deployment target, build script for our project and create multiple target (Main app, Unit Test, Notification, etc) in this file. For each function, you can read the official documentation.
In setting.yml
we configure information for our app in Xcode like bundle identifier, code sign style, provisioning profile name, etc. We can make group for each target so when we have multiple target it can be easier to maintain.
We use configuration file in our project to manage configuration between each environment. So configs.yml
are for setup our configuration file so Xcode can read them later.
Last but not least, schemes.yml
is used for setup our schemes in Xcode. Here we have 3 schemes (Alpha, Beta, Production), and each schemes have different configuration.
Running Script
After you create our .yml
file, you have to run xcodegen using terminal command. Simple run is like this :
xcodegen generate
But because in our project we use cocoapods, we have to run pod install
manually after running xcodegen. So we create a script to automate xcodegen and pod install using script. Create a file with the name makefile
and add this script inside it. Run it with terminal inside your project folder.
first_install
is for developer who is checkout this project for the first time. It will install the necessary library and run xcodegen script.install
is for developer when they checkout another branch from the repository. The different is xcodegen library will not installed again.
As for bootstrap
command, it will install xcodegen and mint into your mac. Create file with the name Mintfile
and add this 2 source library.
I would recommend any team to try out XcodeGen, as although implementing a tool such as XcodeGen can seem overwhelming at first because it changes how you configure your project. However, I can assure you that you will reap its benefits from day one — especially if you work in a modular application and a large team. The time and hassle saved in the future is more than worth it.
Moreover, another benefit is that since you need to specify the entire project configuration through code, you automatically document your project configuration. And we reduced the amount of manual intervention to a minimum when adding a dependency, as now you only need to add the dependencies to definitions of targets that really use them
Thanks for reading!