Keeping it DRY with Objective-C Categories

The iPad app I’m working on has several screens where I need to make asynchronous HTTP requests. For a nice user experience, I need to show some sort of “please wait” message so the user knows something is going on.

To do this, I built a simple UIViewController with a xib that has a transparent black background, rounded corners, a UIActivityIndicatorView, and a UILabel for the message.

Since I have several screens where I’ll need to use this, I created a simple Objective-C Category to mix in my new view to any UIViewController.

Header:



#import <Foundation/Foundation.h>

@class SpinnerViewController;

@interface UIViewController (SpinnerView)

-(void) showSpinnerView:(NSString *)text;
-(void) showSpinnerView;
-(void) hideSpinnerView;

@end

Implementation:



#import "UIViewController+SpinnerView.h"
#import "SpinnerViewController.h"

@implementation UIViewController (SpinnerView)

-(void) showSpinnerView:(NSString *)text {
SpinnerViewController *vc = [[SpinnerViewController alloc] initWithNibName:@”SpinnerViewController” bundle:nil];
vc.view.center = self.view.center;
vc.label.text = text;
[self.view addSubview:vc.view];
[vc release];
}

-(void) showSpinnerView {
[self showSpinnerView:@"Saving..."];
}

-(void) hideSpinnerView {
NSArray *subviews = self.view.subviews;
[[subviews lastObject] removeFromSuperview];
}

@end

Then, in any view controller, adding spinners is as easy as this:

#import "UIViewController+SpinnerView.h"

...

[self showSpinnerView];
[self hideSpinnerView];

SpinnerView Category

Ruby on Rails Validations in Objective-C

I’ve uploaded my MMValidation project to Github. It’s an easy way to get Rails-style validations on any subclass of NSObject.

You declare validations like this:

+(void)initialize {
    [Person validatesPresenceOf:@"firstName"];
    [Person validatesPresenceOf:@"lastName"];
}

And check them like this:

if ([myObject valid]) {
    // yay! proceed as planned
} else {
    // handle the validation errors
}

Click here to get it. Hope you enjoy!

Cloud Notes iPhone App for Rackspace Email

I’m a note fanatic. Any time I have an idea or need to jot down an address, parking spot number, or anything else, I go straight for my phone and start typing. Since I consider my notes to be very important, I’ve always wanted to build an Internet-backed notes app so I wouldn’t have to worry if I dropped my phone in the Bay or messed it up so badly that I needed to restore from scratch.

Luckily, Rackspace provides a Notes service with Rackspace Email! So, we got in touch and started working on what is now my primary notes app for the iPhone.

I submitted it to the App Store today, so hopefully you’ll get to enjoy it soon. It’s a basic notes app that stays in sync with your Rackspace Email notes, but stays out of the way so you don’t need to think about the details of it talking to the service. Using this app feels the same on a subway or airplane with no Internet access as it does sitting at your desk at home next to your wireless router.

Here’s some screen shots!

Rackspace Cloud 1.1 Released

Rackspace Cloud 1.1 is now available in the App Store! Let me know if you like it, hate it, or have any suggestions.

Version 1.2 will focus more on Cloud Files, with an emphasis on better navigation and control, as well as creating files (such as images from the camera).

Rackspace Cloud 1.1 Submitted

Tonight I have submitted the Rackspace Cloud 1.1 update to the App Store. Here are the key new features:

  • The Launch SSH Server button works (assuming you have an ssh app such as iSSH that supports launching via URL)
  • Support for Spanish, French, and German
  • View CDN-enabled images and documents
  • Listen to CDN-enabled audio
  • Email links to CDN-enabled files
  • Email CDN-enabled files as attachments

Here’s a short video demonstrating some of the new features:

Rackspace Cloud 1.1 from Michael Mayo on Vimeo.

Version 1.2 will be all about creating content for Cloud Files.

If you’d like to contribute, or just see how it works, you can view the source on GitHub.

jskeystore

jskeystore is a simple Javascript library I built to store data in a client-side database in Mobile Safari in a way that feels like memcached and hides the complexities and verbosity of using sqlite.

It’s very simple to use. Here is some example code:


var cache = new JSKeyStore();
var person = { first_name: 'Mike', last_name: 'Mayo' };
cache.set('person', person);

cache.get('person', function(obj) {
person = obj;
});

cache.destroy('person');

Behind the scenes, this creates a ‘person’ table with one row and one column that contains the JSON string of the person object.

It is available on GitHub.

Rackspace Cloud App En Español

The 1.1 update to the app is currently in beta (let me know if you’d like to join the beta!) and in the meantime, Héctor Paz has been kind enough to help out by translating the app to Spanish! So, if your iPhone’s default language is Español, you’ll be able to manage your Rackspace Cloud account in your native tongue :)

Cloud File view in Spanish

To see how it was done, take a look at the source on GitHub.

Rackspace Cloud 1.1 iPhone Screen Shots

Here are a couple of screen shots from the first update to the iPhone app. I’m still working on it, so I’m not sure when the first update will be submitted to Apple.

The majority of the effort is going into improving support for Cloud Files.

View Cloud Files

View Cloud Files

Rackspace Cloud iPhone App Goes Open Source

Rackspace Cloud github graph

The source code for the Rackspace Cloud iPhone app is now available on GitHub. If you have the iPhone SDK, feel free to download it if you want to track the progress of new features as they’re developed, or if you have a good idea and you’d like to pitch in!

Right Click to Upload to Cloud Files in Mac OS X

I found a neat utility for uploading images to S3 in Snow Leopard, so I decided to modify it to work with Cloud Files. It’s built in Automator, so click here to get it. After you install it, you should be able to upload things to Cloud Files very easily.

If you change your API Key, go into Keychain Access and delete the cf_service item so you can reset it for the tool.

Download Cloud Files Upload Service for Snow Leopard

screenshot of Cloud Files upload service