Automatic Build Numbers In Xcode

As part of the project I’m working on at the moment I wanted a way to automatically update a targets build number in Xcode. My preferred setting for the build number is the current SCM revision, the script below automatically updates the build number in the Info.plist file each time the application is built.

Just add the script as a ‘Run Script’ build phase for your chosen target in Xcode. The script is only designed for Git, SVN & Git-SVN as they’re all I use at the moment.

#!/bin/bash

#
# Automatically sets the build number for a target in Xcode based
# on either the Subversion revision or Git hash depending on the
# version control system being used
#
# Simply add this script as a 'Run Script' build phase for any
# target in your project
#

git status
if [ "$?" -eq "0" ]
then

    git svn info
    if [ "$?" -eq "0" ]
    then
        buildNumber=$(git svn info | grep Revision | awk '{print $2}')
    else
        buildNumber=$(git rev-parse HEAD | cut -c -10)
    fi
elif [ -d ".svn" ]
then
    buildNumber=$(svn info | grep Revision | awk '{print $2}')
else
    buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" Source/Application-Info.plist)
fi

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" Source/Application-Info.plist

Check back soon.

Automatic Build Numbers In Xcode

Open Sourcing A Few Projects

I’ve finally gotten around to it, writing another blog post, almost one year since the last post containing any meaningful content. Rather than apologising for the hiatus and promising to blog more I will instead move on to something more interesting.

Last year I took the decision to open source two of my main projects, iSyncIt and Set Icon. I didn’t make a big deal about doing it, in fact, I didn’t make any ‘deal’ at all, I just set the GitHub repos to ‘public’. Consider this the (6 months late) announcement of their open sourcing.

The iSyncIt repository contains almost the complete history of iSyncIt development. Unfortunately I started development of iSyncIt before I discovered version control and as a result some of the history is only available as source code bundles in the downloads area.

Fortunately Set Icon development started after I had discovered the advantages of version control so its full development history can be seen in the GitHub repository.

Both of the projects have a fairly non-restrictive license, you can read it in either repository. The downloads section on GitHub for both projects also contains all of the versions of the applications I have ever publicly released.

Now for something a little more current.

This afternoon I flicked the switch that open sourced my final-year university project, Chroma32 (under the same license as the other two). The original idea was to create a (dissertation-grand sounding) ‘photographic asset management system’, the scope eventually morphed into creating a document management system that was as extensible as possible.

The whole project was built around alpha & beta versions of Rails 3 and the alpha-version gems that go along with it. Overall I ended up with a themeable system with reasonably tight integration for complex plugins.

If you want to discover more, clone a copy from its GitHub repo and hack away.

Check back soon, go on, it might actually be worth it from now on. I promise.

Open Sourcing A Few Projects

Rich Text File (RTF) Into NSTextView, Cocoa & Obj-C

I was searching for an example of how to do this for ages and came up with nothing. All the pros out there will probably say it is easy and give shorter ways of doing this but for noobs and people not in the know I wrote this little snippet. This is especially useful for creating easy to maintain change logs or for adding simple read-me and help files to your application.

First of all you will need to create a NIB file with some sort of controller class in it. In the controller class create an outlet of type ‘NSTextView’, for this example I will call it ‘controller_Out_TextView’. Then generate the files for this controller so they appear in your Xcode project.

Secondly, create a window and add an NSTextView to it from the palette, connect the NSTextView to the outlet in the controller.

You will then need to create your rich text file with the necessary text in it, make sure it is added to your project and will be copied to the application bundle. For this example the text file will be called (rather originally) file.rhtml.

Finally add the following code to the ControllerName.m file between the @implementation and @end, or in your awakeFromNib method, if you already have one.

- (void)awakeFromNib
{
  NSBundle * myMainBundle = [NSBundle mainBundle];
  NSString * rtfFilePath = [myMainBundle pathForResource:@"file" ofType:@"rtf"];
  [controller_Out_TextView readRTFDFromFile:rtfFilePath];
}

Compile and run, hoepfully all of your text will be displayed.

Rich Text File (RTF) Into NSTextView, Cocoa & Obj-C