Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift Cookbook

You're reading from   Swift Cookbook Over 50 hands-on recipes to help you create apps, solve problems, and build your portfolio of projects in Swift

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher
ISBN-13 9781784391379
Length 392 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Xcode and Swift FREE CHAPTER 2. Standard Library and Collections 3. Using Structs and Generics 4. Design Patterns with Swift 5. Multitasking 6. Playground 7. Swift Debugging with Xcode 8. Integrating with Objective-C 9. Dealing with Other Languages 10. Data Access 11. Miscellaneous Index

Adding a control version system to an existing project

It's very common starting a project without any version control, and with the passage of time, we change our idea and decide to add one.

Unfortunately, Xcode doesn't give this option to us and we have to do by hand. I hope this option will be added on Xcode soon.

Getting ready

To do this recipe, let's create an empty project called Chapter1 Git; however, this time before we save the project, uncheck the option Create Git CGRepository on.

Getting ready

How to do it...

Follow these steps for creating a local repository on an existing project:

  1. Open a Finder window again and use the shortcut command + Shift + U, or open the utilities folder from your Launchpad. Now, open the terminal and go to your project folder.
  2. Change your folder using the terminal by typing cd followed by a white space. Now, without closing your terminal, open the Finder window, then go to your project folder, drag the folder from the title bar to your terminal window, and then press the Enter key.
    How to do it...
  3. Now, just type the following commands:
    git init
    git add .
    git commit -m "Initial commit"
  4. Now, you can open your project and notice that Xcode already recognizes the VCS. If you want to be sure of it, modify a file, save it with command + S and check that you have the letter M on the right side of your file on the project navigator.
    How to do it...
  5. Once you are happy with your changes, you can deliver them by right-clicking on AppDelegate.swift, then go to the Source Control option and select Commit AppDelegate.swift.
    How to do it...
  6. Then, a dialog asking for a description will appear, write about your modification as comment, and click on commit 1 file.

How it works...

Unfortunately, if you forgot to add a Git repository to your project, Xcode doesn't provide any mechanism to add it to your project, so you have to add it by hand. Opening the command line allows you to use Git from the command line and Xcode detects that this feature has been added. Some versions of Xcode can only detect that the version control has been added when you open your project, so if you've done all steps and Xcode hasn't detected it, try closing and opening Xcode again.

Tip

Xcode offers you some features to work with Git and SVN, but they are very limited. If you need more commands from your VCS, you can use them from the command line, or use an external tool for it.

There's more...

Even if you are not going to work as part of a team, I recommend that you use a version control system. When developing with Swift or other languages, you sometimes need to rollback or compare the current code with the previous versions of it, mainly when you have a new bug.

If you would like to know more on this topic, check out the book Git Version Control Cookbook, by Packt Publishing.

You have been reading a chapter from
Swift Cookbook
Published in: Apr 2015
Publisher:
ISBN-13: 9781784391379
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image