Saturday, May 16, 2015

A Simple Swift iOS App from Start to Finish - Using Source Control in Xcode 6

Introduction

This is part of a series of articles detailing the creation of a simple iOS app. A complete list  of articles is included in the first part A Simple Swift iOS App from Start to Finish - Introduction.

I have set up a web site for the finished app at http://DaysWithoutThings.com and you can download it free directly from the app store:


In this article I am going to  discuss how I am going go use Xcode's  source control facility for my App.


Enabling Source Control

Source control can be enabled during the project creation process. It is given as an option on the final 'Create' step in the project creation  wizard:


Xcode source control uses Git repositories. The project creation wizard gives the option of either using a remote Git repository for the project or creating a new local repository. 




I am going to use the the local repository. This is created in a hidden .git directory in the root directory of the new project.






The Initial Commit

The project creation wizard automatically commits the source code files it creates to the new repository. This can be seen by clicking 'History..' on the main menu's Source Control submenu. 





Seeing what needs to be committed

The Project Navigator displays letters after the names of files that have been altered since the last source control commit.



New files that have not been committed yet have an 'A' for 'Add' listed after them and files that have been modified since their last commit have an 'M' for modified. A+ denotes files that were already in Source Control that have been renamed. Files that are deleted are removed from the Project Navigator so there is no visual indication of their source control status. However their deletion is tracked for source control purposes and will be included in the next commit.

 

Committing Changes

Changes can be committed by either right clicking the affected files and selecting Source Control | Commit "filename" or selecting Commit... from the main menu's source control menu.
I am going to be committing my changes as part of the wrap up section to each of my articles. When I select Commit... it opens the commit window which lists all the files that have been added, modified or deleted since my last commit together with a display of the differences between the current versions of the files and the version in the repository. It also include an input area for a comment to include with the commit.


Viewing Revision History

I can view the history of my commits by selecting the History... option on the main Source Control menu. This shows me a list of all the commits I've made together with the comments I made when I committed them.



If I click on the 'Show x modified files' text next to a commit it will open the a window that will show the files included in that commit together with a difference viewer.






The Version Editor

I can also see the history of each file by switching to the version editor.


Wrapping up

As my app is such a small project that I do not expect to be using any of the advanced features of the source control system. However if you want to learn more Apple have posted a couple of videos here:

https://developer.apple.com/videos/wwdc/2012/?id=411

https://developer.apple.com/videos/wwdc/2013/?id=414


In my next article  I will move on to renaming the default view controller class.

Next:       A Simple Swift iOS App from Start to Finish - Refactoring the ViewController's name

No comments:

Post a Comment