Building Web Apps With Objective-C

Matthew Campbell, December 20, 2011

There are two camps when it comes to Objective-C programmers: the lovers and the haters.  This post is for all the Objective-C lovers out there.

Did you know that you can make web apps with Objective-C?

Let’s back up for one second: if you haven’t built a web app yet you should realize that there are lots of ways to do this.  The most basic is to use a combination of HTML, JavaScript, CSS and a backend web service of come kind to craft an app that will be used in a user’s browser.  These technologies are standardized so you can make sure you’re app will work with any user’s browser if you are careful.

There are other higher level platforms available to you that you can use to make web apps.  Ruby On Rails is a popular solution along with PHP, .NET, Java and probably hundreds more.  In fact, it’s possible that the platform you work with now has support for web apps.

Objective-C programmers however find out quickly that XCode and Apple doesn’t have support for web based apps of any kind.  For Objective-C and Cocoa enthusiasts this is a real bummer.

But Wait! Objective-J Saves The Day

Objective-What?  Objective-J is a programming language that is based on Objective-C that is designed to work with web apps.  The J comes from the idea that Objective-J is a higher level interface for Javascript.  Javascript is kind of a mess, but when you put Objective-J on top of Javascript coding web apps can be an elegant experience.

For example, here is code that you would use to set up a basic Hello World App using Objective-J code:

@import <Foundation/CPObject.j>

@implementation AppController : CPObject{
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification{

    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
        contentView = [theWindow contentView];

    var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];

    [label setStringValue:@"Hello World!"];
    [label setFont:[CPFont boldSystemFontOfSize:24.0]];

    [label sizeToFit];

    [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [label setCenter:[contentView center]];

    [contentView addSubview:label];

    [theWindow orderFront:self];

}

@end

When you run this app in Safari you get this:

Pretty Cool Huh? You can download the demo where this code is hosted from the Cappuccino Web Framework site. This site is the hub for Objective-J and Cappuccino development. Cappuccino is the name of the web framework that is used with Objective-J to make web apps.

Objective-C is the programming language and you use to make iOS app with Cocoa and Cocoa-Touch, while Objective-J is the programming language that you use to make web apps with Cappuccino. Objective-J and Cappuccino follow the same design patterns as Objective-C and Cocoa.

Impression Of Objective-J, Cappuccino and Web Apps

First things first: this is not a cross-platform solution and the purpose of this project is not to let you copy and paste your Mac app code to be used in a web app. In fact, you probably won’t use any of the XCode tools to work with this. Objective-J and Cappuccino are completely separate from the desktop and mobile tools, so you may end up using a different toolset to code these web apps.

That being said, from what I’ve seen so far this is a very powerful and cohesive way to make web apps. The framework is very rich and it really looks and feels like desktop app code. It’s well worth your time if you are very comfortable with Objective-C programming already and want to be able to quickly deploy polished looking web apps.

The best thing to do is download and try out some of the demos at the Cappuccino Web Framework website.  Let me know what you think and how this compares with other web frameworks for apps.

What are your impressions of Objective-J and Cappuccino?