skip main content

Posts Tagged ‘development’

Logging/Debug setup in Xcode 4

posted by Duncan at 9:10 am on May 31st, 2011

Here’s a little snippet of how I manage logging in my applications with Xcode 4. I’m sure it works just fine in 3 too, but this is more of a reminder for me as it’s something I always forget how to do when starting a new project.

Firstly I update the *_Prefix.pch file that lives in the Other Resources directory so it also contains the snippet below. I use the Prefix code posted by Marcus Zarra which seems to work just fine for me:

#ifdef DEBUG
  #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
  #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
  #define DLog(...) do { } while (0)
  #define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)

Next I update my project by adding the DEBUG=1 flag to the preprocessor settings. Click on your application target, and select the Build Settings tab is selected along with All and Combined. I then do a search for ”- preprocessing” which should leave you with the Preprocessor Macros remaining. Now just DEBUG-1 to the correct one, as the photo below shows.

DEBUG flag

Hope that saves someone some time. Oh, and if anyone has any improvements I can make to this, I’d love to here them.

Language, Timothy! A simple Google Wave robot

posted by Duncan at 10:47 pm on January 3rd, 2010

In late May last year Google first announced ‘Google Wave‘ at their IO conference. If you haven’t already, I advise you read all about it, and watch the introductory video.

Now I heard about GW early on, but didn’t really make any time for myself to understand the concept, or find out about the inner workings. In fact, like may people I know, I just thought it was an exercise in swapping invites, and once I had one, and had a very quick play, I didn’t get it.

Well, now I’ve read all the documentation, watched the videos, understood the concept, I tend to agree with the team. This could indeed be a gamer changer. We do need something to replace the increasingly old fashion email (40 years old), and this not only does that, but merges in a whole bunch of tasks and possibilities as well. It could be the future.

Now for developers, one of the things that GW comes with is the Wave API. The API allows you to use and enhance GW in a couple of ways. By extensions, or by embedding GW in other web pages.

So in order to understand the API more, I thought I’d build a simple Extension. In this case a robot, that when added to your GW conversation, will remove all the bad words it catches people using. This simple example starts allowing me to understand how the API works, and how I interact with Waves, Wavelets and Blips.

Google Wave Robot

Now, it is a very simple example of what’s possible via the API and what will be possible in GW, but it’s a good example of how you get up and running with the Python SDK. I am of course assuming you have a App Engine account, and downloaded the SDK.

If you’d like to see the robot in action in a wave, just add the contact:

and then add this contact as a participant in your wave conversation you want monitoring. I only tried it in conversation with myself, but I’m sure it’ll be fine. The robot is also in the wave sample gallery.

As always, grab the code over at Github.

BBC Gardeners’ Planner in your calendar part deux

posted by Duncan at 1:01 pm on October 20th, 2009

This is just a small extension to the original post: Subscribe to the BBC Gardeners’ Planner with the help of Sinatra.

I mentioned there that I needed to add some caching to the application, and also that it didn’t live anywhere. Well it now has caching (a feeds cached for a day) thanks to rack/cache and it now has a url:

Which you can now use in your iCal enabled calendar, one of which is Google Calendar, which is used in the photo below where I have subscriber to:

Google Calendar

I was having some strange problems the other day, where Google Calendar was showing the calendar titles as long email addresses. I think this may be a Google Calendar index thing (anyone know?), as it appears to fix itself over time so ignore it.

Subscribe to the BBC Gardeners’ Planner with the help of Sinatra

posted by Duncan at 9:45 am on October 15th, 2009

[UPDATE] I have posted an update with a url you can use

I really like being in my garden, so I was looking at the BBC Gardening site the other day for some gardening tips. The hardest part for me, is the lack of experience I have in knowing what needs to be done and when.

The BBC Gardening website solves this by having a gardeners’ planner. Great I thought, there’s loads of really useful stuff in there. The problem is I have to keep going back to the site, to check what I’m suppose to be doing. As it’s a planner, it would be great of I could have this information to put in my own calendar, so I could see it along with other jobs I have to do. Even better if I could subscribe to this information, so if it ever changes, I’m kept up-to-date. Maybe they will provide this one day (I really think they should), but in the mean time I decided to roll my own:

Subscribing to the BBC Garden planner

I’ve created a web app that reads this planner data, and converts it into the iCal format that you can now subscribe to. It’s written using Sinatra, and I choose to run it under the awesome Passenger via mod_passenger. It’s currently not hosted anywhere (other than on my laptop), so you’ll have to run it on your own server. Maybe that will change if I can find somewhere to stick it, I’ll keep you posted. I think some caching may be needed before that happens though.

Once running on your computer of choice, you only really have one uri to stick in your calendar of choice. You can extend this uri by passing in section names to filter the information displayed in the calendar. Here’s a few examples:

# to subscribe to a calendar of everything ( quite big! )
# to subscribe to a calendar of tips on just trees, ponds and wildlife
# to view all the available sections

And here’s what it looks like in Apple’s iCal once you have subscibed:

BBC Garden planner in iCal

Get your own copy of the app from github. You get up and running in the same way you would with any Sinatra/Passenger app. The structure and config file is already written, so you really just need to do the vhost and symlinking :

Happy Gardening!

My first puzzle game KeyCell is now in the App Store

posted by Duncan at 11:13 am on October 9th, 2009

After the fun I had building my last iPhone app, I thought I’d have a go and writing a puzzle game. I bring you KeyCell.

KeyCell is based on a puzzle game I remember seeing in a ActionScript book about 8 years ago. It’s a kind of reverse Tetris. Touch a cell that has adjacent cells of the same colour to make them disappear. The more cells that you remove in one go, the more points you get. The challenge is to try and clear all the cells and achieve the highest score.

Now this appears simple, but actually, to get the real high scores you really have to think about it, making sure you remove the cells in such away that they setup the next bunch of coloured cells to remove. Here’s a screen shot of the game in action:

KeyCell for iPhone and iPod touch

You can also share your scores with the world. This option is off by default, as I wanted the game to be as simple as possible out of the box, but you can turn on the feature via the settings page. The score are then submitted to cocosLive. Check out the scores.

Thanks once again go out to David Wilson who created the wonderful App Icon. I asked him in passing if he’d be interested in creating an icon, and a few days later it popped into my inbox, thankyou again David.

The game is written using the iPhone cocos2d game framework. This was something I’ve never used before, but has been a very enjoyable experience to use. If you want to write iPhone games, this is certainly a good starting point.

Hydrate – An iPhone app that helps you manage your daily water intake

posted by Duncan at 9:05 am on August 15th, 2009

My train journey to work over the last couple of months, plus help from a couple of friends, has resulted in my first iPhone Application. Hydrate is in the App Store now.

It’s a simple concept. Hydrate helps you manage your daily water intake. Something I don’t do, hence the app. You can use it to keep track of how much water you drink a day. Every time you have a drink, you just log it with the app. You set goals, get a summary of your drinking habits as well as being able to look back over previous days. Simple!

Coming up with a new app idea that isn’t in the App Store is pretty much impossible now. When I started mine, there were no others that did the same, but there now appears to be a couple.

So, please give it a try. I’d love to know what you think.


Oh and if you didn’t click on the links, it has it’s own website:

I need to thank my friends David Wilson and David Johnson for their help with the app, as well as everyone who helped with the different language translations.

Mr Wilson helped me realise the design of the app, and was very patient with me. Although I had a picture of what I wanted the app to look like, and how I expected it to function in my head, without his input and ideas, it wouldn’t of looked as polished as it does now. He also created the new app icon that will be in V1.1.

That counts of Mr Johnson too. He rendered the glass tumbler and sliced it into manageable layers to allow the water to be seen inside. Again, I knew what I wanted but did not have the skills to make it. As you can see from the final rendering, he did! He also created a great transition animation, which I hope to incorporate.

I really enjoyed the experience of developing on the iPhone, so I’m now working on a couple of new apps which will be completed at some point during future train journeys to work. One is a game using the cocos2d library and the other is for teachers. I’ll leave it there. Stay tuned.

Another iPhone Code Sign Error Fix solution

posted by Duncan at 3:10 pm on May 10th, 2009

Dam, this took far to long to suss out !!! I even left the London Open Hack 2009 early because I was unable to install development apps I was working on onto my iPhone, and it was proving so frustrating I decided to go home to try and fix it there … Dam!!!

So the error I was getting was:

Code Sign error: The identity 'iPhone Developer' doesn't match any valid 
certificate/private key pair in the default keychain

I won’t bore you with all the variations, forums, websites read and ways I tried to solve this, and will leave you with the solution in this case. The problem was that the KeyChain App had changed it’s default keychain over to ‘system‘ and it should have been ‘login‘ as this is where all my keys and certificates are installed. Also, the default keychain is where Xcode looks. The default keyChain in the one in the keychains list that is bold. To make one the default, you right click on it and select the ‘make default’ item from the list.

Yep, That’s It!! and to be honest the error message make a little more sense now I’ve fixed it … Dam!

Controlling the spotlights at work with Sinatra and OSC

posted by Duncan at 8:47 pm on April 24th, 2009

Nic bought some spotlights the other week for work, so we could hook them up to our continuous integration server, and they would let us know using the medium of colour, when things had failed!

Before we did that, I thought I’d have a little play. Tristan and Chris having been building a fun new game (Read more via the Radio Labs blog soon) which uses nowplaying data from BBC 6 Music to power it. Knowing when a track is starting and ending is also useful, so as a bit of fun, I wrote a little Ruby script that made the spotlights behave like traffic lights:

  1. Green – when a track started playing
  2. Flashing Amber – when a track was about to finish
  3. Red – when the track finally finished

spotlightPhoto by Tristan

To control the lights we’re using ROSC open sound control for Ruby. It’s very good, but required building to install, and the interface is nice, but not simple enough if all you’re doing is turning a light on or off and changing it’s colour. So in order to make the script even more simple, I thought I’d write a little http proxy so that your could control the lights by just going to a url. It meant even the non-programmers could have fun replicating disco lighting. The urls look like this:


The proxy is written using Sinatra. I love Sinatra. If you thought prototyping was simple with Rails, well with Sinatra + Passenger it takes simplicity to a whole new level.

You can download the lightcontroller source from Github as normal, you’ll have to tweak a few settings for your needs. You may even find it a useful template for controlling something else.

RevCanonical 1.2, Customise your link tag plus a little more

posted by Duncan at 10:33 am on April 23rd, 2009

I’ve made a few updates to the RevCanonical WordPress plugin I built. These updates add a bit of extra functionality, and also allowed me to tidy up the documentation, so that people know what they’re getting.

First update, is the ability to customise how the link tag is constructed within the head of your page. This is due to the large amount of people who have contacted me, asking why I choose to use rev=canonical and not rel= shorturl, rel=shorturl or rel=short_url etc. As I told them, the reason I chose rev=canonical was to be honest simply because I liked it, and many of my peers were already using this method on their sites. Simple.

So currently with the plugin you get this out of the box:

<link rev="canonical" type="text/html"  href="" />

but you could customise it to be like this:

<link rel="shorturl" href="" />

The reason for this extra customisation is to try and stop people being distracted by the what attribute should I use conversation, and start getting them hosting their own short links they can use. This at least starts solving one problem. When a general consensus, or in deed a standard appears about the attributes, you can simple update and you’re good-to-go.

At the moment the only place you can see the shortened url is either by looking in the source, or using a bookmarklet like the one Simon wrote. I guess I could of injected the url into the admin interface somewhere, but I generally don’t want to see it. The idea is, it’s there for machines to see if they need to, and if I really need to pass it around I’ll just use the bookmarklet.

If you want more flexibility, I have added a of a couple of tags you can use in your templates. These simply let you display the shortened url for a specific post.

# echo the shortened url to the screen
<?php get_revcanonical_shorturl($post_id); ?>
# assign the shortened url to a variable
<?php $url = revcanonical_shorturl($post_id); ?>

Oh and finally, just a reminder that this plugin plays well with the TweetMe plugin I wrote that tweets to when you publish a post, and will check to see if you have the RevCanonical plugin installed. If you do, it will use your own shortened url instead of the version.

Using Cocoa to keep an app window always on top

posted by Duncan at 4:39 pm on April 11th, 2009

Sometimes you want your application to keep one of it’s windows always-on-top. A chat application like Adium for example, allows you to keep your conversation window always-on-top so you can follow the conversation whilst still using other applications. In the TellyBox application I wrote, this functionality is also very useful, as you can watch tv whilst still working in other applications.

So the basic implementation was fairly simple. You just use the windowDidResignMain notification, and then re-set the window level a more fitting one. Below I have also wrapped around a preference setting:

- (void)windowDidResignMain:(NSNotification *)notification
  // It's always nicer if the user has a choice
  if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAlwaysOnTop"] == YES) {
    [[self window] setLevel:NSFloatingWindowLevel];
  } else {
    [[self window] setLevel:NSNormalWindowLevel];

My TellyBox application allows you to go fullscreen via the existing Flash application embedded in a webkit view. Using just the basic implementation meant that when going into fullscreen mode the frame of the original window remained in view. To fix this I added this extra bit of code, which gets used via the firing of another useful notification windowDidBecomeMain :

- (void)windowDidBecomeMain:(NSNotification *)notification
  [[self window] setLevel:NSNormalWindowLevel];

which sets the window level back to it’s default value of 0 when it becomes the main window i.e when you select it.

I hope this little snippet helps people trying to achieve the same effect in their apps.

back to the top