Xcode 9: Adding Your Project to GitHub

February 21st, 2018

Filed under: Version Control, Xcode | Be the first to comment!

Before Xcode 9, setting up your project to work on GitHub involved a lot of work. You had to login to GitHub, create a repository, go back to your Mac, launch the Terminal application, navigate to your project directory, and run multiple git commands.

Xcode 9 makes working with GitHub much easier. You can add your Xcode project to GitHub without leaving Xcode.

Start by going to the source control navigator by choosing View > Navigators > Show Source Control Navigator.


Select the Remotes folder, right-click, and choose Create Remote on GitHub. A sheet similar to the following will open:


Unless you’ve already configured a GitHub account in Xcode, choose Add a GitHub Account from the Account menu.


Enter your GitHub account name and password. Click the Sign In button to use your GitHub account for this repository.

Choose public visibility unless you have a paid GitHub account. You must have a paid account to create private GitHub repositories.

Click the Create button to create the remote branch. Your Xcode project is now on GitHub.

Want to Learn More About Version Control?

I’m writing a book, Version Control for iOS and Mac Developers, that provides a gentle guide to using version control. Unlike other books, this book is geared towards iOS and Mac developers. Go to the book’s website to sign up for the newsletter to get tips on using version control and a free excerpt from the book when it’s finished.


Handling Swipe Gestures in a SpriteKit Game

February 16th, 2018

Filed under: Game Development, iOS Development | Be the first to comment!

When you create a SpriteKit Xcode project, the GameScene.swift file contains functions to handle touch and/or mouse events, depending on the type of SpriteKit project you create. You can also use swipe gestures in SpriteKit games. Supporting swipe gestures requires you to perform two tasks.

The first task is to create a swipe gesture recognizer. The swipe gesture recognizer takes two arguments: a target and a selector (function) to call when someone performs the gesture. Set the swipe gesture recognizer’s direction and add it to the view. The following code demonstrates how to create a swipe gesture recognizer for swiping right:

override func didMove(to view: SKView) {
    let swipeRight = UISwipeGestureRecognizer(target: self, 
        action: #selector(GameScene.swipeRight(sender:)))
    swipeRight.direction = .right

The second task is to write a function to handle the swipe.

@objc func swipeRight(sender: UISwipeGestureRecognizer) {
    // Handle the swipe

The functions to handle the swipes need the @objc at the start because they’re selectors that access the Objective-C runtime.


Creating a Git Repository for an Existing Xcode Project

February 12th, 2018

Filed under: Version Control, Xcode | Be the first to comment!

When you create a new Xcode project, Xcode gives you the option to create a git repository on your Mac.


How do you create a git repository for a project after the project has been created?

Choose Source Control > Create Git Repositories. A sheet opens.


Click the Create button and Xcode will create a git repository for your project.


Using agvtool to Update Version and Build Numbers

February 5th, 2018

Filed under: Xcode | Be the first to comment!

Apple bundles a command-line tool with Xcode, agvtool, to automatically update your project’s version and build numbers. This article shows you how to use agvtool in your Xcode projects.

Enabling agvtool in Your Project

Before you can use agvtool, you must tell Xcode to use it for your project. To enable agvtool, change the following build settings:

  • Set the Versioning System build setting to Apple Generic.
  • Give the Current Project Version build setting an initial value. Agvtool works best with integer build numbers. 1 is a good choice.


Updating the Build Number

Because agvtool is a command-line tool, you have to run it from the Terminal application. Navigate to your project’s directory before running agvtool.

The most common thing you will be doing in agvtool is incrementing the build number. Run agvtool with the next-version -all option to increment the build number.

agvtool next-version -all

To set the build number to a specific value, supply the desired build number. The most common reason for explicitly setting a build number is to use non-integer build numbers. The following example sets the build number to 8.2:

agvtool next-version -all 8.2

The what-version option lets you see the current build number.

agvtool what-version

Updating the Version Number

To update the version number of your project, run agvtool with the new-marketing-version option and supply the version number. The following example sets the version to 0.5:

agvtool new-marketing-version 0.5

The what-marketing-version option lets you see the current version number.

agvtool what-marketing-version

Report a Bug to Apple from Xcode

January 31st, 2018

Filed under: Xcode | Be the first to comment!

In Xcode choose Help > Report an Issue to send a bug report to Apple.

I’m not sure when this menu item was added to Xcode. I know it’s available in Xcode 9.2.