How to create an iOS Template Repository
Easy and quick step by step guide to create an iOS template repository
If you’re working on a team, is probable that when a new project is about to kick off the first thing that you need to do is create a git repository and upload the initial Xcode setup. For an iOS project, we usually include some common libraries or utilities, we do some sort of setup for environments, etc. Most of the time, this task is pretty similar for all the projects.
We can take advantage of the templates repositories feature that GitHub provides. A template repository will allow us to get a new project up more quicker, so we can focus on starting the actual developing process and not wasting too much time on making configurations that are shared for every project.
In this article, I want to show you how you can easily create and configure a template repository for your iOS projects.
GitHub Template Repo
First things first, we need to create a new repository. This is the one that will serve as a template for other projects.
- Go to GitHub and create a new repository. Choose a name that you want, for example,
ios-template
. - Create all the branches that you want. For example, you may want to have a
develop
. Once you have that done, you also can set up the branching permission. - In addition, you can create a pull request template if you want to every project follow the same standard.
- Once you’ve set all the configurations that you want, go to the repo’s settings and check the
Template repository
check box. - Finally, you will see a new option on the repository home page: Use this template.
Xcode Template Project
Now that we have our template repository created, it’s time to create our Xcode template project. Go ahead and create a brand new project from Xcode, make sure you choose the same name as you chose for the repository. In our example it is ios-template-project
Now it’s time to configure the base project. I’m not going into details here, the things that you can add to the template project it’s up to you and your team’s needs. However, here is a list of some of the project settings that we use at Houlak for our development process.
- Environments: We usually have three: Dev, QA, and Prod. For each environment, we have a list of settings like backend endpoints, third-party libs, etc. that are configured in .plist files.
- Schemes: If you use different schemes to match your environments (as we do) you can include those in the template project as well. You might have to put some generic names there that will need to rename when the actual project repo will be createded.
- Utilities & libraries: If you have some common utilities or libs (like Alamofire) that you use on all your projects, you can include them.
- Third-Party project setup: If you use some third-party service like Crashlytics or Sentry, it will be a good addition to the template project.
These are just a few settings that we share across all our projects, you basically can add anything that fits your needs.
Once you have the template project done, just push it to GitHub.
Create project from template
The next time that you need to start a new project you can create it from the template repository directly. Once you’ve done that, there’re a few steps that you need to do to complete the setup.
- Clone the repo into your local machine.
- Rename the Xcode project. You can do this by clicking the project name on the left panel navigation. Once you hit enter, Xcode will prompt a confirmation alert.
- In our example, rename the
ios-template
folder with your project name. - Rename the project’s target.
- Change any default placeholder with your project name. For example, in our template, we need to rename the scheme names.
And that’s all you need! You also can include these configurations steps in your template repository’s Readme.
Summary
As you can see, creating a template repository is a pretty easy task and will save you a good amount of time in the future. You just need to pick the configurations that you want to include and create a template project, only one time!. If in the future you want to modify your template it will be easy to do.
Also, it will bring standards to all of your projects , because it will be following the same settings, which over time will be easier to maintain.