A Whirlwind Introduction to git submodules

I have put off learning how to use git submodules for too long, but one of my projects has been crying out for them for so long that I finally had to act.

The project IDZAQAudioPlayer demonstrates how to use the IDZPrecompiledOgg and IDZPrecompiledVorbis frameworks to play Ogg Vorbis audio. Before using submodules, the frameworks were manually copied into the IDZAudioPlayer/Frameworks directory and checked into the repository.

Adding Submodules

Adding submodules is relatively simple. Change to the directory where you want the submodules to reside and use git submodule add command.

You can simplify the names of the directories for the submodules. For example:

Cloning a Repository with Submodules

Cloning a repository that uses submodules requires a few extra steps. After cloning the repository.

Change into the working directory.

Then initialize and update the submodules.


Posted in git | Tagged , | Leave a comment

Getting Travis CI Working with Your iOS GitHub Builds in Under 10 Minutes

I try to make sure that all my Open Source repositories on GitHub compile and run correctly, but it is easy to miss some dependency on my system or some other bug. So it’s nice to have the ability to build on a fresh virtual machine, automatically, each time I push. This is exactly what Travis Continuous Integration (CI) offers and it’s free for Open Source projects! I had dragged my heels about figuring out his to use Travis. I envisaged torturous configuration files and long hours of frustration. I was wrong. In this post I will explain how you can get a basic Travis build working for an iOS project hosted on GitHub. It should take you less that 10 minutes.

Ensure Your Code Builds Locally

The first step is to ensure that you can successfully build from the command line on your local machine. Check out a fresh copy of your repository, change directory to where your project file is and issue the following command (substituting your build scheme name for ADZAQAudioPlayer of course).

If this goes well you are ready to proceed, otherwise fix any problems.

Make Your Build Scheme Shared

By default, your build schemes are not checked into source code control, so they are not available to Travis via GitHub. To change this go to Product > Scheme > Manage Schemes… and check the Shared check box for any schemes you want to include in your build.

Check the Shared box to share you build scheme.

Check the Shared box to share you build scheme.

Write Your .travis.yml File

The Travis build file, .travis.yml, is very straightforward. You need to specify language: objective-c to ensure your build is run on a Mac; if your forget this it will be scheduled on a Linux VM. You can optionally have an install section where you can install any dependencies needed for you build. The most important part of the build file is the script section which tells Travis which commands to run to execute your build. Each command is prefaced with a - (this is part of the YAML format).

The most basic Xcode build file will look like this:

If IDZAQAudioPlayer had tests, these could also be run by appending the following to the file.

Sign On to the Travis Website and Enable Integration

To sign in to Travis go to https://travis-ci.org and click the Sign in with GitHub item in the top right corner. The first time you do this it will ask you to confirm access to GitHub and perhaps a few other questions. Once this is complete, go to the Accounts section. You can get there by choosing Accounts from the drop down menu that appears when you hover on your avatar in the top left corner of the screen.

Click the Sign in with GitHub item.

Click the Sign in with GitHub item.

The accounts section should list all your repositories at GitHub; if it does not you may need to press the Sync Now button. Then flip the switch beside the project you want Travis to monitor.

Flip the switch to turn on Travis integration.

Flip the switch to turn on Travis integration.

Push to GitHub

To test your build, commit the .travis.yml file you created earlier and push to GitHub. You build should appear on the Travis site momentarily and begin executing. You can monitor the build’s progress on the Travis site by clicking the spanner/wrench icon beside the switch for the project and choosing the tab.

Monitoring a Travis Build

Monitoring a Travis Build

Adding Build Status Icon to README.md

Clicking on the build status indicator (it looks something like this Travis build status indicator) brings up a dialog that allows to copy code to paste into web sites, mark down documents or blogs. Choose the Markdown option and paste it close to the top of your repository README.md. You can also use it to create a page displaying the status of all your builds. I do this for my repositories on the Open Source page.

Obviously this post only scratches the surface of what you can do with Travis, be sure to explore the documentation on their site. I hope I saved you some time with this quick introduction. If I did please consider visiting one of our sponsors’ sites or contributing directly to this site on Gratipay .


Posted in Tutorial | Leave a comment

Swift Standard Library: transcode

Swift Standard Library: transcode

The transcode function lets to convert strings from one Unicode encoding to another, for example UTF16 to UTF8.

The definition you get when you command-click on the function is quite intimidating:

It is also incorrect; a type constraint with the same type expression on both sides of the == sign is not much of a constraint.

In plain English, what these constraints are saying is that we need an input
source (a GeneratorType) that generates elements that are compatible with
our input UnicodeCodecType and an output SinkType that can consume the output of our output encoder.

The following code takes the UTF32 codepoint for the “Grinning Face with Smiling Eyes”
emoji (I’m not kidding that is its official name!) and converts it to UTF8.

The values obtained seem to agree with the values I found on the ‘net, but we can verify using Cocoa to construct a string from the UTF8 values

In the playground for this tutorial the above code will print the emoji.

Download the Playground

The source for this and all other playgrounds in this series can be found on Github in the SwiftStandardLibraryPlaygrounds repository.


Posted in Swift, Swift Standard Library | Tagged , , , , , , | 1 Comment