Enums and Switches

If you are one to use enum to define modes or types in your models or controllers, consider using switch statements to help branch the different behaviors. If you do so, the complier will help you when you have forgotten to implement behavior for a enum value.

Take for example a view controller that might have different behavior if we are in an editing mode, and even more so the editing is handled differently depending on the target device. For this, let’s create an enum like:

typedef enum ViewControllerMode : NSUInteger {
    ViewControllerModeDefault = 0,
} ViewControllerMode;

Now if the tableView:didSelectRowAtIndexPath: method let’s use a switch statement to branch behavior depending on the behaviorMode.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    switch (self.behaviorMode) {
        case ViewControllerModeDefault:
            [self showRecordAtIndexPath:indexPath];
        case ViewControllerModeEditingiPhone:
            [self editRecordAtIndexPath:indexPath];
        case ViewControllerModeEditingiPad:
            [self replaceRecordAtIndexPath:indexPath];

Notice we are not using a switch default behavior here. Now let’s add a new enum type called ViewControllerModeEditingiWatch and compile. Tada! The complier has a warning for us.

Enumeration value 'ViewControllerModeEditingiWatch' not handled in switch

This pattern can be extremely helpful to make sure you are accounting for all needed behaviors. Please consider it next time you are working with enum. Thanks!

Setup Bots Status as a Screensaver

It’s time to turn off that family photo screensaver and switch to something that’s important, CI status screens!

Bots Big Screen

First up you’ll need this screensaver (or something similar), which can be configured to load a single or multiple websites up as a screensaver.


Sadly the screensaver bundle is not developer signed so if you are bit paranoid consider downloading, inspecting and building the thing from source. Or you could be like me and hit run inside of Security after the initial “can’t run, not signed” dialogue.

Next you’ll need some URLs. I run both Xcode Bots and Jenkins off my Mac mini named GLaDOS and for those you’ll want URLs like:



For Jenkins I’m currently using the Build Monitor Plugin which is pretty basic but a nice start.

Here’s to hoping all your returns from coffee breaks are bathed in green and passing tests.

Xcode Bots and Branches

Just a little quick tip tonight. If you create a Bot from within Xcode 5 it will assume that the branch you want this Bot to run on is the branch you are currently on. To change this, use the Xcode Bot Web interface. Select your Bot and look for the settings gear in the upper right and then edit the Bot, defining which branch you want to bot to run on.

Xcode Bot Setting Gear

Xcode Bot Setting Details

I’m starting to revive an old side project of mine and it’s feeling good so far. I have Xcode Bots running tests and the static analyzer (all green baby!). I also have Jenkins deploying to HockeyApp when I merge development into my qa branch. Hope to share more details soon.