Version Control for iOS Projects

Why Version Control Is Important

Imagine the situation: You’ve created an app for the iPhone or iPad, tested it and submitted it to the App Store. It’s going well. People are downloading it and giving it good reviews. In fact it’s going so well that you’ve decided to concentrate all your development time on adding a series of cool new features. You are working hard on the changes but you are still a couple of weeks away from being able to submit your update.

Then you start to notice that iTunes Connect, the application that you use to monitor and manage releases on the App Store, is showing crash logs for the released version. You look at the reviews and somebody has given you a one star review because your application crashes in certain situations. Oh no! You need to make a fix — quickly. Unfortunately, you’ve made so many changes that it’s not easy to go forward or backward. By the time you unravel everything, you could find yourself with a poorly rated app that nobody will want to download.

This is where version control comes in.

Version Control in Xcode

From version 4, the iOS development tool Xcode has built-in support for the Git version control system and offers the option of creating a Git repository on project creation. For applications that you intend to release to the App Store, you should consider this an essential step.

Git was written by Linus Torvalds, the creator of Linux, specifically to manage versioning in the Linux kernel. Unlike some other version control systems, it provides a distributed architecture with no need to maintain a central server. It is also very efficient when it comes to branching and tagging (with 15 million lines of code in the Linux kernel it has to be). This makes it a great choice as a lightweight version control system for iOS projects.

Working with Git

Different people use branches in different ways but I tend to start development in the master (otherwise known as trunk) branch. When the app is ready for release, I tag the master branch with the version number and submit it for review. From then on, new features are developed in a development branch which is only merged into the master when it’s ready for submission. So the master is always in sync with the latest release and I can go back to any released version using the tags.

In the scenario described above, the master would be branched to a bug fix branch to write and test the fix. If the tests went well, this would be merged back into the master and tagged with a new version number before the fix was submitted. That done it’s easy to check out the development branch and continue the development of more cool new features. Panic over!

Because branches are so easy to create with Git, they also come in handy for testing experimental features. Branch the development branch into an experimental branch. If your crazy idea works out, merge it back into development. If it doesn’t, just delete the experimental branch and pick up where you left off. Once you start using Git for version control, you’ll wonder how you ever managed without it.

Xcode 4 provides simple shortcuts for easy committing of changes during development and also allows you to manage your project’s Git repository through the Repositories tab in the Organizer window. You can create branches, switch branches, merge changes from other branches and look at differences between revisions.

Other Tools

If you are already a Git expert, you can manage the Git repository from the terminal by issuing Git commands in your project directory. There are also a number of applications on the Mac App Store that provide visual views of your repository state, e.g., SourceTree from Atlassian.

You won’t need to use version control when you create applications in our iPhone® and iPad® Programming: A Comprehensive Hands-On Introduction and Building iPhone® and iPad® Applications: Extended Features courses, but all of the instructors manage apps on the App Store and would be happy to share their experiences.

Richard Senior

Type to search blog.learningtree.com

Do you mean "" ?

Sorry, no results were found for your query.

Please check your spelling and try your search again.